﻿using System;
using System.Collections.Generic;
using Poly2Tri;
using UnityEngine;

namespace UltimateFracturing
{
	// Token: 0x02000425 RID: 1061
	public static class Fracturer
	{
		// Token: 0x06001DEA RID: 7658 RVA: 0x000B7A44 File Offset: 0x000B5C44
		public static void CancelFracturing()
		{
			object obj = Fracturer.s_FracturingStats;
			lock (obj)
			{
				Fracturer.s_FracturingStats.bCancelFracturing = true;
			}
		}

		// Token: 0x06001DEB RID: 7659 RVA: 0x000B7A84 File Offset: 0x000B5C84
		public static bool IsFracturingCancelled()
		{
			bool result = false;
			object obj = Fracturer.s_FracturingStats;
			lock (obj)
			{
				result = Fracturer.s_FracturingStats.bCancelFracturing;
			}
			return result;
		}

		// Token: 0x06001DEC RID: 7660 RVA: 0x000B7AC8 File Offset: 0x000B5CC8
		public static bool FractureToChunks(FracturedObject fracturedComponent, bool bPositionOnSourceAndHideOriginal, out List<GameObject> listGameObjectsOut, Fracturer.ProgressDelegate progress = null)
		{
			listGameObjectsOut = new List<GameObject>();
			bool flag = false;
			GameObject sourceObject = fracturedComponent.SourceObject;
			Mesh mesh = null;
			if (sourceObject)
			{
				MeshFilter component = fracturedComponent.SourceObject.GetComponent<MeshFilter>();
				if (component)
				{
					mesh = Fracturer.CopyMesh(component);
					mesh.name = string.Format("mesh_{0}{1}", fracturedComponent.SourceObject.gameObject.name, fracturedComponent.SourceObject.gameObject.GetInstanceID().ToString());
				}
			}
			if (fracturedComponent.FracturePattern == FracturedObject.EFracturePattern.BSP)
			{
				flag = Fracturer.FractureToChunksBSP(fracturedComponent, bPositionOnSourceAndHideOriginal, out listGameObjectsOut, progress);
			}
			if (fracturedComponent.SingleMeshObject != null)
			{
				UnityEngine.Object.DestroyImmediate(fracturedComponent.SingleMeshObject);
			}
			if (flag && !Fracturer.IsFracturingCancelled())
			{
				fracturedComponent.OnCreateFracturedObject();
				fracturedComponent.SingleMeshObject = UnityEngine.Object.Instantiate<GameObject>(fracturedComponent.SourceObject);
				fracturedComponent.SingleMeshObject.name = "@" + fracturedComponent.name + " (single mesh)";
				fracturedComponent.SingleMeshObject.transform.localPosition = fracturedComponent.transform.position;
				fracturedComponent.SingleMeshObject.transform.localRotation = fracturedComponent.transform.rotation;
				fracturedComponent.SingleMeshObject.transform.localScale = fracturedComponent.SourceObject.transform.localScale;
				fracturedComponent.SingleMeshObject.transform.parent = fracturedComponent.transform;
				foreach (Component component2 in fracturedComponent.SingleMeshObject.GetComponents<Component>())
				{
					if (component2.GetType() != typeof(Transform) && component2.GetType() != typeof(MeshRenderer) && component2.GetType() != typeof(MeshFilter))
					{
						UnityEngine.Object.DestroyImmediate(component2);
					}
				}
				MeshFilter component3 = fracturedComponent.SingleMeshObject.GetComponent<MeshFilter>();
				component3.sharedMesh = mesh;
				fracturedComponent.SingleMeshObject.SetActive(true);
			}
			return flag;
		}

		// Token: 0x06001DED RID: 7661 RVA: 0x000B7CD0 File Offset: 0x000B5ED0
		private static Mesh CopyMesh(MeshFilter meshfIn)
		{
			Mesh mesh = new Mesh();
			Vector3[] vertices = meshfIn.sharedMesh.vertices;
			Vector3[] normals = meshfIn.sharedMesh.normals;
			Vector4[] tangents = meshfIn.sharedMesh.tangents;
			Vector2[] uv = meshfIn.sharedMesh.uv;
			Vector2[] uv2 = meshfIn.sharedMesh.uv2;
			Color[] colors = meshfIn.sharedMesh.colors;
			Color32[] colors2 = meshfIn.sharedMesh.colors32;
			if (vertices != null && vertices.Length > 0)
			{
				Vector3[] array = new Vector3[vertices.Length];
				vertices.CopyTo(array, 0);
				mesh.vertices = array;
			}
			if (normals != null && normals.Length > 0)
			{
				Vector3[] array2 = new Vector3[normals.Length];
				normals.CopyTo(array2, 0);
				mesh.normals = array2;
			}
			if (tangents != null && tangents.Length > 0)
			{
				Vector4[] array3 = new Vector4[tangents.Length];
				tangents.CopyTo(array3, 0);
				mesh.tangents = array3;
			}
			if (uv != null && uv.Length > 0)
			{
				Vector2[] array4 = new Vector2[uv.Length];
				uv.CopyTo(array4, 0);
				mesh.uv = array4;
			}
			if (uv2 != null && uv2.Length > 0)
			{
				Vector2[] array5 = new Vector2[uv2.Length];
				uv2.CopyTo(array5, 0);
				mesh.uv2 = array5;
			}
			if (colors != null && colors.Length > 0)
			{
				Color[] array6 = new Color[colors.Length];
				colors.CopyTo(array6, 0);
				mesh.colors = array6;
			}
			if (colors2 != null && colors2.Length > 0)
			{
				Color32[] array7 = new Color32[colors2.Length];
				colors2.CopyTo(array7, 0);
				mesh.colors32 = array7;
			}
			mesh.subMeshCount = meshfIn.sharedMesh.subMeshCount;
			for (int i = 0; i < meshfIn.sharedMesh.subMeshCount; i++)
			{
				int[] triangles = meshfIn.sharedMesh.GetTriangles(i);
				int[] array8 = new int[triangles.Length];
				triangles.CopyTo(array8, 0);
				mesh.SetTriangles(array8, i);
			}
			return mesh;
		}

		// Token: 0x06001DEE RID: 7662 RVA: 0x000B7ED4 File Offset: 0x000B60D4
		private static bool FractureToChunksBSP(FracturedObject fracturedComponent, bool bPositionOnSourceAndHideOriginal, out List<GameObject> listGameObjectsOut, Fracturer.ProgressDelegate progress = null)
		{
			listGameObjectsOut = new List<GameObject>();
			MeshFilter component = fracturedComponent.SourceObject.GetComponent<MeshFilter>();
			if (component == null)
			{
				return false;
			}
			Fracturer.s_FracturingStats = new Fracturer.FracturingStats();
			Fracturer.s_FracturingStats.nTotalChunks = fracturedComponent.GenerateNumChunks;
			if (progress != null)
			{
				progress("Fracturing", "Initializing...", 0f);
			}
			foreach (FracturedChunk fracturedChunk in fracturedComponent.ListFracturedChunks)
			{
				if (fracturedChunk != null)
				{
					UnityEngine.Object.DestroyImmediate(fracturedChunk.gameObject);
				}
			}
			fracturedComponent.ListFracturedChunks.Clear();
			fracturedComponent.DecomposeRadius = (component.sharedMesh.bounds.max - component.sharedMesh.bounds.min).magnitude;
			UnityEngine.Random.InitState(fracturedComponent.RandomSeed);
			FracturedChunk component2 = fracturedComponent.gameObject.GetComponent<FracturedChunk>();
			int num = (!(component2 != null)) ? -1 : component2.SplitSubMeshIndex;
			if (num == -1 && fracturedComponent.SourceObject.GetComponent<Renderer>() && fracturedComponent.SourceObject.GetComponent<Renderer>().sharedMaterial == fracturedComponent.SplitMaterial)
			{
				num = 0;
			}
			Fracturer.SplitOptions @default = Fracturer.SplitOptions.Default;
			@default.bVerticesAreLocal = false;
			Vector3 position = fracturedComponent.transform.position;
			Quaternion rotation = fracturedComponent.transform.rotation;
			Vector3 position2 = fracturedComponent.SourceObject.transform.position;
			fracturedComponent.SourceObject.transform.position = Vector3.zero;
			fracturedComponent.transform.position = fracturedComponent.SourceObject.transform.position;
			fracturedComponent.transform.rotation = fracturedComponent.SourceObject.transform.rotation;
			Material[] aMaterials = (!fracturedComponent.SourceObject.GetComponent<Renderer>()) ? null : fracturedComponent.SourceObject.GetComponent<Renderer>().sharedMaterials;
			MeshData meshData = new MeshData(component.transform, component.sharedMesh, aMaterials, fracturedComponent.SourceObject.transform.localToWorldMatrix, true, num, true);
			Queue<MeshData> queue = new Queue<MeshData>();
			Queue<int> queue2 = new Queue<int>();
			if (fracturedComponent.GenerateIslands)
			{
				CombinedMesh component3 = fracturedComponent.SourceObject.GetComponent<CombinedMesh>();
				if (component3 != null)
				{
					component3.TransformObjInfoMeshVectorsToLocal(fracturedComponent.SourceObject.transform.transform);
					List<MeshData> list = new List<MeshData>();
					for (int i = 0; i < component3.GetObjectCount(); i++)
					{
						CombinedMesh.ObjectInfo objectInfo = component3.GetObjectInfo(i);
						MeshData meshDataIn = new MeshData(component.transform, objectInfo.mesh, objectInfo.aMaterials, fracturedComponent.transform.localToWorldMatrix * objectInfo.mtxLocal, true, -1, true);
						List<MeshData> list2 = Fracturer.ComputeMeshDataIslands(meshDataIn, false, fracturedComponent, progress);
						foreach (MeshData item in list2)
						{
							queue.Enqueue(item);
							queue2.Enqueue(0);
							list.Add(item);
						}
					}
					if (fracturedComponent.GenerateChunkConnectionInfo)
					{
						for (int j = 0; j < list.Count; j++)
						{
							if (progress != null)
							{
								progress("Fracturing", "Processing combined object chunks connectivity...", (float)j / (float)list.Count);
								if (Fracturer.IsFracturingCancelled())
								{
									return false;
								}
							}
							for (int k = 0; k < list.Count; k++)
							{
								if (j != k)
								{
									Fracturer.ComputeIslandsMeshDataConnectivity(fracturedComponent, false, list[j], list[k]);
								}
							}
						}
					}
				}
				else
				{
					List<MeshData> list3 = Fracturer.ComputeMeshDataIslands(meshData, false, fracturedComponent, progress);
					foreach (MeshData item2 in list3)
					{
						queue.Enqueue(item2);
						queue2.Enqueue(0);
					}
				}
			}
			else
			{
				queue.Enqueue(meshData);
				queue2.Enqueue(0);
			}
			Fracturer.s_FracturingStats.nChunkCount = 1;
			bool generateIslands = fracturedComponent.GenerateIslands;
			while (queue.Count < Fracturer.s_FracturingStats.nTotalChunks)
			{
				if (Fracturer.IsFracturingCancelled())
				{
					break;
				}
				MeshData meshDataIn2 = queue.Dequeue();
				int num2 = queue2.Dequeue();
				if (progress != null)
				{
					progress("Fracturing", string.Format("Computing chunk {0}/{1} (Depth {2})", Fracturer.s_FracturingStats.nChunkCount + 1, Fracturer.s_FracturingStats.nTotalChunks, (!generateIslands) ? num2.ToString() : ": size ordered traversal"), Mathf.Clamp01((float)Fracturer.s_FracturingStats.nChunkCount / (float)Fracturer.s_FracturingStats.nTotalChunks));
				}
				int nSplitAxis = -1;
				Matrix4x4 randomPlaneSplitMatrix = Fracturer.GetRandomPlaneSplitMatrix(meshDataIn2, fracturedComponent, out nSplitAxis);
				List<MeshData> list4;
				List<MeshData> list5;
				if (Fracturer.SplitMeshUsingPlane(meshDataIn2, fracturedComponent, @default, randomPlaneSplitMatrix.MultiplyVector(Vector3.up), randomPlaneSplitMatrix.MultiplyVector(Vector3.right), randomPlaneSplitMatrix.MultiplyPoint3x4(Vector3.zero), out list4, out list5, progress))
				{
					Fracturer.s_FracturingStats.nSplitCount++;
					foreach (MeshData item3 in list4)
					{
						queue.Enqueue(item3);
					}
					queue2.Enqueue(num2 + 1);
					foreach (MeshData item4 in list5)
					{
						queue.Enqueue(item4);
					}
					queue2.Enqueue(num2 + 1);
				}
				if (generateIslands)
				{
					List<MeshData> list6 = new List<MeshData>();
					while (queue.Count > 0)
					{
						list6.Add(queue.Dequeue());
					}
					list6.Sort(new MeshData.DecreasingSizeComparer(nSplitAxis));
					foreach (MeshData item5 in list6)
					{
						queue.Enqueue(item5);
					}
				}
				Fracturer.s_FracturingStats.nChunkCount = queue.Count;
			}
			MeshData[] array = queue.ToArray();
			if (!Fracturer.IsFracturingCancelled())
			{
				for (int l = 0; l < array.Length; l++)
				{
					GameObject gameObject = Fracturer.CreateNewSplitGameObject(fracturedComponent.SourceObject, fracturedComponent, fracturedComponent.SourceObject.name + (l + 1), true, array[l]);
					gameObject.AddComponent<Rigidbody>();
					gameObject.GetComponent<Rigidbody>().isKinematic = true;
					listGameObjectsOut.Add(gameObject);
				}
				if (fracturedComponent.GenerateChunkConnectionInfo)
				{
					Fracturer.ComputeChunkConnections(fracturedComponent, listGameObjectsOut, new List<MeshData>(array), progress);
				}
				fracturedComponent.ComputeChunksRelativeVolume();
				fracturedComponent.ComputeChunksMass(fracturedComponent.TotalMass);
				fracturedComponent.ComputeSupportPlaneIntersections();
			}
			if (fracturedComponent.AlwaysComputeColliders)
			{
				Fracturer.ComputeChunkColliders(fracturedComponent, progress);
			}
			bool flag = Fracturer.IsFracturingCancelled();
			fracturedComponent.SourceObject.transform.position = position2;
			if (bPositionOnSourceAndHideOriginal)
			{
				fracturedComponent.gameObject.transform.position = fracturedComponent.SourceObject.transform.position;
				fracturedComponent.gameObject.transform.rotation = fracturedComponent.SourceObject.transform.rotation;
				fracturedComponent.SourceObject.SetActive(false);
			}
			else
			{
				fracturedComponent.transform.position = position;
				fracturedComponent.transform.rotation = rotation;
			}
			return !flag;
		}

		// Token: 0x06001DEF RID: 7663 RVA: 0x000B86FC File Offset: 0x000B68FC
		public static List<MeshData> ComputeMeshDataIslands(MeshData meshDataIn, bool bVerticesAreLocal, FracturedObject fracturedComponent, Fracturer.ProgressDelegate progress)
		{
			MeshFaceConnectivity meshFaceConnectivity = new MeshFaceConnectivity();
			MeshDataConnectivity meshDataConnectivity = new MeshDataConnectivity();
			List<int>[] array = new List<int>[meshDataIn.aaIndices.Length];
			List<VertexData> list = new List<VertexData>();
			for (int i = 0; i < meshDataIn.nSubMeshCount; i++)
			{
				array[i] = new List<int>();
				for (int j = 0; j < meshDataIn.aaIndices[i].Length / 3; j++)
				{
					int num = meshDataIn.aaIndices[i][j * 3];
					int num2 = meshDataIn.aaIndices[i][j * 3 + 1];
					int num3 = meshDataIn.aaIndices[i][j * 3 + 2];
					int nVertexHash = meshDataIn.aVertexData[num].nVertexHash;
					int nVertexHash2 = meshDataIn.aVertexData[num2].nVertexHash;
					int nVertexHash3 = meshDataIn.aVertexData[num3].nVertexHash;
					Vector3 v3Vertex = meshDataIn.aVertexData[num].v3Vertex;
					Vector3 v3Vertex2 = meshDataIn.aVertexData[num2].v3Vertex;
					Vector3 v3Vertex3 = meshDataIn.aVertexData[num3].v3Vertex;
					array[i].Add(num);
					array[i].Add(num2);
					array[i].Add(num3);
					if (fracturedComponent.GenerateChunkConnectionInfo)
					{
						meshDataConnectivity.NotifyNewClippedFace(meshDataIn, i, j, i, j);
					}
					meshFaceConnectivity.AddEdge(i, v3Vertex, v3Vertex2, nVertexHash, nVertexHash2, num, num2);
					meshFaceConnectivity.AddEdge(i, v3Vertex2, v3Vertex3, nVertexHash2, nVertexHash3, num2, num3);
					meshFaceConnectivity.AddEdge(i, v3Vertex3, v3Vertex, nVertexHash3, nVertexHash, num3, num);
				}
			}
			list.AddRange(meshDataIn.aVertexData);
			meshDataIn.meshDataConnectivity = meshDataConnectivity;
			List<MeshData> list2 = MeshData.PostProcessConnectivity(meshDataIn, meshFaceConnectivity, meshDataConnectivity, array, list, meshDataIn.nSplitCloseSubMesh, meshDataIn.nCurrentVertexHash, false);
			if (fracturedComponent.GenerateChunkConnectionInfo)
			{
				for (int k = 0; k < list2.Count; k++)
				{
					if (progress != null)
					{
						progress("Fracturing", "Processing initial island connectivity...", (float)k / (float)list2.Count);
						if (Fracturer.IsFracturingCancelled())
						{
							return new List<MeshData>();
						}
					}
					for (int l = 0; l < list2.Count; l++)
					{
						if (k != l)
						{
							Fracturer.ComputeIslandsMeshDataConnectivity(fracturedComponent, bVerticesAreLocal, list2[k], list2[l]);
						}
					}
				}
			}
			return list2;
		}

		// Token: 0x06001DF0 RID: 7664 RVA: 0x000B8940 File Offset: 0x000B6B40
		public static void ComputeChunkColliders(FracturedObject fracturedComponent, Fracturer.ProgressDelegate progress)
		{
			int num = 0;
			int num2 = 0;
			Fracturer.s_FracturingStats = new Fracturer.FracturingStats();
			foreach (FracturedChunk fracturedChunk in fracturedComponent.ListFracturedChunks)
			{
				if (Fracturer.IsFracturingCancelled())
				{
					break;
				}
				if (progress != null)
				{
					progress("Computing colliders", string.Format("Collider {0}/{1}", num + 1, fracturedComponent.ListFracturedChunks.Count), (float)num / (float)fracturedComponent.ListFracturedChunks.Count);
				}
				if (!(fracturedChunk == null))
				{
					if (fracturedChunk.GetComponent<Collider>() != null)
					{
						MeshCollider component = fracturedChunk.GetComponent<MeshCollider>();
						if (component)
						{
							component.sharedMesh = null;
						}
						if (fracturedChunk.GetComponent<Collider>())
						{
							UnityEngine.Object.DestroyImmediate(fracturedChunk.GetComponent<Collider>());
						}
					}
					if (fracturedChunk.GetComponent<Rigidbody>() != null)
					{
						UnityEngine.Object.DestroyImmediate(fracturedChunk.GetComponent<Rigidbody>());
					}
					while (fracturedChunk.transform.childCount > 0)
					{
						UnityEngine.Object.DestroyImmediate(fracturedChunk.transform.GetChild(0).gameObject);
					}
					fracturedChunk.HasConcaveCollider = false;
					bool flag = false;
					Fracturer.RemoveEmptySubmeshes(fracturedChunk);
					if (fracturedChunk.Volume > fracturedComponent.MinColliderVolumeForBox)
					{
						if (fracturedComponent.IntegrateWithConcaveCollider)
						{
							int num3 = ConcaveColliderInterface.ComputeHull(fracturedChunk.gameObject, fracturedComponent);
							if (num3 > 0)
							{
								fracturedChunk.HasConcaveCollider = true;
								flag = true;
								num2 += num3;
							}
						}
						else
						{
							MeshFilter component2 = fracturedChunk.GetComponent<MeshFilter>();
							if (component2 != null && component2.sharedMesh != null && component2.sharedMesh.vertexCount >= 3)
							{
								fracturedChunk.HasConcaveCollider = false;
								MeshCollider meshCollider = fracturedChunk.gameObject.AddComponent<MeshCollider>();
								meshCollider.convex = true;
								flag = true;
								if (meshCollider.sharedMesh)
								{
									num2 += meshCollider.sharedMesh.triangles.Length / 3;
								}
								meshCollider.isTrigger = (fracturedComponent.ChunkColliderType == FracturedObject.ColliderType.Trigger);
							}
						}
					}
					if (!flag)
					{
						BoxCollider boxCollider = fracturedChunk.gameObject.AddComponent<BoxCollider>();
						num2 += 12;
						boxCollider.isTrigger = (fracturedComponent.ChunkColliderType == FracturedObject.ColliderType.Trigger);
					}
					if (fracturedChunk.GetComponent<Collider>())
					{
						fracturedChunk.GetComponent<Collider>().material = fracturedComponent.ChunkPhysicMaterial;
					}
					fracturedChunk.gameObject.AddComponent<Rigidbody>();
					fracturedChunk.GetComponent<Rigidbody>().isKinematic = true;
					num++;
				}
			}
			if (!Fracturer.IsFracturingCancelled())
			{
				fracturedComponent.ComputeChunksMass(fracturedComponent.TotalMass);
			}
			if (fracturedComponent.Verbose && fracturedComponent.ListFracturedChunks.Count > 0)
			{
				Debug.Log(string.Concat(new object[]
				{
					"Total collider triangles: ",
					num2,
					". Average = ",
					num2 / fracturedComponent.ListFracturedChunks.Count
				}));
			}
		}

		// Token: 0x06001DF1 RID: 7665 RVA: 0x000B8C5C File Offset: 0x000B6E5C
		public static void DeleteChunkColliders(FracturedObject fracturedComponent)
		{
			foreach (FracturedChunk fracturedChunk in fracturedComponent.ListFracturedChunks)
			{
				while (fracturedChunk.transform.childCount > 0)
				{
					UnityEngine.Object.DestroyImmediate(fracturedChunk.transform.GetChild(0).gameObject);
				}
				if (fracturedChunk.GetComponent<Collider>() != null)
				{
					UnityEngine.Object.DestroyImmediate(fracturedChunk.GetComponent<Collider>());
				}
				if (fracturedChunk.GetComponent<Rigidbody>() != null)
				{
					UnityEngine.Object.DestroyImmediate(fracturedChunk.GetComponent<Rigidbody>());
				}
			}
		}

		// Token: 0x06001DF2 RID: 7666 RVA: 0x000B8D18 File Offset: 0x000B6F18
		private static Matrix4x4 GetRandomPlaneSplitMatrix(MeshData meshDataIn, FracturedObject fracturedComponent, out int nSplitAxisPerformed)
		{
			Vector3 zero = Vector3.zero;
			Quaternion quaternion = Quaternion.identity;
			Vector3 vector = meshDataIn.v3Min - meshDataIn.v3Position;
			Vector3 vector2 = meshDataIn.v3Max - meshDataIn.v3Position;
			if (!fracturedComponent.SplitsWorldSpace)
			{
				vector = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
				vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
				Matrix4x4 inverse = Matrix4x4.TRS(meshDataIn.v3Position, meshDataIn.qRotation, meshDataIn.v3Scale).inverse;
				for (int i = 0; i < meshDataIn.aVertexData.Length; i++)
				{
					Vector3 vector3 = inverse.MultiplyPoint3x4(meshDataIn.aVertexData[i].v3Vertex);
					if (vector3.x < vector.x)
					{
						vector.x = vector3.x;
					}
					if (vector3.y < vector.y)
					{
						vector.y = vector3.y;
					}
					if (vector3.z < vector.z)
					{
						vector.z = vector3.z;
					}
					if (vector3.x > vector2.x)
					{
						vector2.x = vector3.x;
					}
					if (vector3.y > vector2.y)
					{
						vector2.y = vector3.y;
					}
					if (vector3.z > vector2.z)
					{
						vector2.z = vector3.z;
					}
				}
			}
			int num = -1;
			if (fracturedComponent.SplitRegularly)
			{
				float num2 = vector2.x - vector.x;
				float num3 = vector2.y - vector.y;
				float num4 = vector2.z - vector.z;
				if (num2 >= num3 && num2 >= num4)
				{
					num = 0;
				}
				else if (num3 >= num2 && num3 >= num4)
				{
					num = 1;
				}
				else
				{
					num = 2;
				}
			}
			else
			{
				for (int j = 0; j < 3; j++)
				{
					float value = UnityEngine.Random.value;
					bool flag = Mathf.Approximately(fracturedComponent.SplitXProbability, 0f);
					bool flag2 = Mathf.Approximately(fracturedComponent.SplitYProbability, 0f);
					bool flag3 = Mathf.Approximately(fracturedComponent.SplitZProbability, 0f);
					if (!flag && (value <= fracturedComponent.SplitXProbability || (flag2 && flag3)))
					{
						num = 0;
					}
					if (!flag2 && num == -1)
					{
						float num5 = fracturedComponent.SplitXProbability + fracturedComponent.SplitYProbability;
						if (value <= num5 || flag3)
						{
							num = 1;
						}
					}
					if (num == -1)
					{
						num = 2;
					}
				}
			}
			nSplitAxisPerformed = num;
			float num6 = 0f;
			float num7 = 45f;
			if (num == 0)
			{
				num6 = (vector2.x - vector.x) * 0.5f;
				quaternion = Quaternion.LookRotation(-Vector3.up, Vector3.right) * Quaternion.Euler(new Vector3(0f, UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitXVariation, UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitXVariation));
			}
			else if (num == 1)
			{
				num6 = (vector2.y - vector.y) * 0.5f;
				quaternion = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitYVariation, 0f, UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitYVariation));
			}
			else if (num == 2)
			{
				num6 = (vector2.z - vector.z) * 0.5f;
				quaternion = Quaternion.LookRotation(-Vector3.up, Vector3.forward) * Quaternion.Euler(new Vector3(UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitZVariation, UnityEngine.Random.Range(-num7, num7) * fracturedComponent.SplitZVariation, 0f));
			}
			num6 = num6 * fracturedComponent.SplitSizeVariation * 0.8f;
			zero = new Vector3(UnityEngine.Random.Range(-1f, 1f) * num6, UnityEngine.Random.Range(-1f, 1f) * num6, UnityEngine.Random.Range(-1f, 1f) * num6);
			if (!fracturedComponent.SplitsWorldSpace)
			{
				return Matrix4x4.TRS(zero + meshDataIn.v3Position, fracturedComponent.SourceObject.transform.rotation * quaternion, Vector3.one);
			}
			return Matrix4x4.TRS(zero + meshDataIn.v3Position, quaternion, Vector3.one);
		}

		// Token: 0x06001DF3 RID: 7667 RVA: 0x000B91B8 File Offset: 0x000B73B8
		private static GameObject CreateNewSplitGameObject(GameObject gameObjectIn, FracturedObject fracturedComponent, string strName, bool bTransformVerticesBackToLocal, MeshData meshData)
		{
			GameObject gameObject = new GameObject(strName);
			MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
			FracturedChunk fracturedChunk = gameObject.AddComponent<FracturedChunk>();
			fracturedChunk.transform.parent = fracturedComponent.transform;
			if (fracturedComponent.SourceObject)
			{
				gameObject.layer = fracturedComponent.SourceObject.layer;
			}
			else
			{
				gameObject.layer = fracturedComponent.gameObject.layer;
			}
			fracturedComponent.ListFracturedChunks.Add(fracturedChunk);
			meshData.FillMeshFilter(meshFilter, bTransformVerticesBackToLocal);
			fracturedChunk.SplitSubMeshIndex = meshData.nSplitCloseSubMesh;
			fracturedChunk.OnCreateFromFracturedObject(fracturedComponent, meshData.nSplitCloseSubMesh);
			gameObject.AddComponent<MeshRenderer>();
			gameObject.GetComponent<Renderer>().shadowCastingMode = gameObjectIn.GetComponent<Renderer>().shadowCastingMode;
			gameObject.GetComponent<Renderer>().receiveShadows = gameObjectIn.GetComponent<Renderer>().receiveShadows;
			gameObject.GetComponent<Renderer>().enabled = false;
			Material[] array = new Material[meshData.nSubMeshCount];
			meshData.aMaterials.CopyTo(array, 0);
			if (meshData.aMaterials.Length < meshData.nSubMeshCount)
			{
				array[meshData.nSubMeshCount - 1] = fracturedComponent.SplitMaterial;
			}
			gameObject.GetComponent<Renderer>().sharedMaterials = array;
			gameObject.GetComponent<Renderer>().lightmapIndex = gameObjectIn.GetComponent<Renderer>().lightmapIndex;
			gameObject.GetComponent<Renderer>().lightmapScaleOffset = gameObjectIn.GetComponent<Renderer>().lightmapScaleOffset;
			gameObject.GetComponent<Renderer>().lightProbeUsage = gameObjectIn.GetComponent<Renderer>().lightProbeUsage;
			return gameObject;
		}

		// Token: 0x06001DF4 RID: 7668 RVA: 0x000B9324 File Offset: 0x000B7524
		private static int CreateMeshConnectivityVoronoiHash(int nCell1, int nCell2)
		{
			int num = Mathf.Max(nCell1, nCell2) + 256;
			int num2 = Mathf.Min(nCell1, nCell2) + 256;
			return num << 16 | num2;
		}

		// Token: 0x06001DF5 RID: 7669 RVA: 0x000B9354 File Offset: 0x000B7554
		private static void ComputeChunkConnections(FracturedObject fracturedObject, List<GameObject> listGameObjects, List<MeshData> listMeshDatas, Fracturer.ProgressDelegate progress = null)
		{
			for (int i = 0; i < listGameObjects.Count; i++)
			{
				if (progress != null)
				{
					progress("Fracturing", "Computing connections...", (float)i / (float)listGameObjects.Count);
				}
				if (Fracturer.IsFracturingCancelled())
				{
					return;
				}
				FracturedChunk component = listGameObjects[i].GetComponent<FracturedChunk>();
				List<FracturedChunk.AdjacencyInfo> list = new List<FracturedChunk.AdjacencyInfo>();
				for (int j = 0; j < listGameObjects.Count; j++)
				{
					if (i != j)
					{
						FracturedChunk component2 = listGameObjects[j].GetComponent<FracturedChunk>();
						float num = 0f;
						bool sharedFacesArea = listMeshDatas[i].GetSharedFacesArea(fracturedObject, listMeshDatas[j], out num);
						bool flag = num >= fracturedObject.ChunkConnectionMinArea;
						if (Mathf.Approximately(fracturedObject.ChunkConnectionMinArea, 0f) && sharedFacesArea)
						{
							flag = true;
						}
						if (flag && sharedFacesArea)
						{
							list.Add(new FracturedChunk.AdjacencyInfo(component2, num));
						}
					}
				}
				component.ListAdjacentChunks = list;
			}
		}

		// Token: 0x06001DF6 RID: 7670 RVA: 0x000B9458 File Offset: 0x000B7658
		private static void RemoveEmptySubmeshes(FracturedChunk fracturedChunk)
		{
			MeshFilter component = fracturedChunk.GetComponent<MeshFilter>();
			if (component == null)
			{
				return;
			}
			Mesh sharedMesh = component.sharedMesh;
			if (sharedMesh.subMeshCount < 2)
			{
				return;
			}
			MeshRenderer component2 = fracturedChunk.GetComponent<MeshRenderer>();
			List<Material> list = new List<Material>();
			List<int[]> list2 = new List<int[]>();
			int num = 0;
			for (int i = 0; i < sharedMesh.subMeshCount; i++)
			{
				int[] indices = sharedMesh.GetIndices(i);
				if (indices != null && indices.Length > 0)
				{
					list.Add(component2.sharedMaterials[i]);
					list2.Add(indices);
				}
				else if (i < fracturedChunk.SplitSubMeshIndex)
				{
					num--;
				}
			}
			sharedMesh.subMeshCount = list2.Count;
			for (int j = 0; j < list2.Count; j++)
			{
				sharedMesh.SetTriangles(list2[j], j);
				component2.sharedMaterials = list.ToArray();
			}
			fracturedChunk.SplitSubMeshIndex -= num;
			component.sharedMesh = sharedMesh;
		}

		// Token: 0x06001DF7 RID: 7671 RVA: 0x000B9568 File Offset: 0x000B7768
		public static bool SplitMeshUsingPlane(GameObject gameObjectIn, FracturedObject fracturedComponent, Fracturer.SplitOptions splitOptions, Transform transformPlaneSplit, out List<GameObject> listGameObjectsPosOut, out List<GameObject> listGameObjectsNegOut, Fracturer.ProgressDelegate progress = null)
		{
			listGameObjectsPosOut = new List<GameObject>();
			listGameObjectsNegOut = new List<GameObject>();
			MeshFilter component = gameObjectIn.GetComponent<MeshFilter>();
			if (component == null)
			{
				return false;
			}
			foreach (FracturedChunk fracturedChunk in fracturedComponent.ListFracturedChunks)
			{
				if (fracturedChunk != null)
				{
					UnityEngine.Object.DestroyImmediate(fracturedChunk.gameObject);
				}
			}
			fracturedComponent.ListFracturedChunks.Clear();
			fracturedComponent.DecomposeRadius = (component.sharedMesh.bounds.max - component.sharedMesh.bounds.min).magnitude;
			UnityEngine.Random.InitState(fracturedComponent.RandomSeed);
			FracturedChunk component2 = gameObjectIn.GetComponent<FracturedChunk>();
			int num = (!(component2 != null)) ? -1 : component2.SplitSubMeshIndex;
			if (num == -1 && gameObjectIn.GetComponent<Renderer>() && gameObjectIn.GetComponent<Renderer>().sharedMaterial == fracturedComponent.SplitMaterial)
			{
				num = 0;
			}
			Material[] aMaterials = (!fracturedComponent.gameObject.GetComponent<Renderer>()) ? null : fracturedComponent.gameObject.GetComponent<Renderer>().sharedMaterials;
			MeshData meshDataIn = new MeshData(component.transform, component.sharedMesh, aMaterials, component.transform.localToWorldMatrix, !splitOptions.bVerticesAreLocal, num, true);
			List<MeshData> list;
			List<MeshData> list2;
			if (!Fracturer.SplitMeshUsingPlane(meshDataIn, fracturedComponent, splitOptions, transformPlaneSplit.up, transformPlaneSplit.right, transformPlaneSplit.position, out list, out list2, progress))
			{
				return false;
			}
			if (list.Count > 0)
			{
				for (int i = 0; i < list.Count; i++)
				{
					GameObject item = Fracturer.CreateNewSplitGameObject(gameObjectIn, fracturedComponent, gameObjectIn.name + "0" + ((list.Count <= 1) ? string.Empty : ("(" + i + ")")), !splitOptions.bVerticesAreLocal, list[i]);
					listGameObjectsPosOut.Add(item);
				}
			}
			if (list2.Count > 0)
			{
				for (int j = 0; j < list2.Count; j++)
				{
					GameObject item2 = Fracturer.CreateNewSplitGameObject(gameObjectIn, fracturedComponent, gameObjectIn.name + "1" + ((list2.Count <= 1) ? string.Empty : ("(" + j + ")")), !splitOptions.bVerticesAreLocal, list2[j]);
					listGameObjectsNegOut.Add(item2);
				}
			}
			return true;
		}

		// Token: 0x06001DF8 RID: 7672 RVA: 0x000B983C File Offset: 0x000B7A3C
		private static bool SplitMeshUsingPlane(MeshData meshDataIn, FracturedObject fracturedComponent, Fracturer.SplitOptions splitOptions, Vector3 v3PlaneNormal, Vector3 v3PlaneRight, Vector3 v3PlanePoint, out List<MeshData> listMeshDatasPosOut, out List<MeshData> listMeshDatasNegOut, Fracturer.ProgressDelegate progress = null)
		{
			Plane planeSplit = new Plane(v3PlaneNormal, v3PlanePoint);
			listMeshDatasPosOut = new List<MeshData>();
			listMeshDatasNegOut = new List<MeshData>();
			bool flag = meshDataIn.nSplitCloseSubMesh == -1;
			int num = meshDataIn.nSplitCloseSubMesh;
			int nCurrentVertexHash = meshDataIn.nCurrentVertexHash;
			List<VertexData> list = new List<VertexData>();
			List<VertexData> list2 = new List<VertexData>();
			List<int>[] array = new List<int>[meshDataIn.nSubMeshCount + ((meshDataIn.nSplitCloseSubMesh != -1) ? 0 : 1)];
			List<int>[] array2 = new List<int>[meshDataIn.nSubMeshCount + ((meshDataIn.nSplitCloseSubMesh != -1) ? 0 : 1)];
			MeshFaceConnectivity meshFaceConnectivity = new MeshFaceConnectivity();
			MeshFaceConnectivity meshFaceConnectivity2 = new MeshFaceConnectivity();
			MeshDataConnectivity meshDataConnectivity = new MeshDataConnectivity();
			MeshDataConnectivity meshDataConnectivity2 = new MeshDataConnectivity();
			list.Capacity = meshDataIn.aVertexData.Length / 2;
			list2.Capacity = meshDataIn.aVertexData.Length / 2;
			if (flag)
			{
				num = meshDataIn.nSubMeshCount;
				array[num] = new List<int>();
				array2[num] = new List<int>();
			}
			Dictionary<EdgeKeyByHash, int> dictionary = new Dictionary<EdgeKeyByHash, int>(new EdgeKeyByHash.EqualityComparer());
			Dictionary<EdgeKeyByHash, CapEdge> dictionary2 = new Dictionary<EdgeKeyByHash, CapEdge>(new EdgeKeyByHash.EqualityComparer());
			Dictionary<EdgeKeyByIndex, ClippedEdge> dictionary3 = new Dictionary<EdgeKeyByIndex, ClippedEdge>(new EdgeKeyByIndex.EqualityComparer());
			Dictionary<EdgeKeyByIndex, ClippedEdge> dictionary4 = new Dictionary<EdgeKeyByIndex, ClippedEdge>(new EdgeKeyByIndex.EqualityComparer());
			int num2 = 0;
			int num3 = 0;
			Dictionary<int, int> dictionary5 = new Dictionary<int, int>();
			Dictionary<int, int> dictionary6 = new Dictionary<int, int>();
			for (int i = 0; i < meshDataIn.nSubMeshCount; i++)
			{
				array[i] = new List<int>();
				array2[i] = new List<int>();
				List<int> list3 = array[i];
				List<int> list4 = array2[i];
				array[i].Capacity = meshDataIn.aaIndices[i].Length / 2;
				array2[i].Capacity = meshDataIn.aaIndices[i].Length / 2;
				int j = 0;
				while (j < meshDataIn.aaIndices[i].Length / 3)
				{
					List<VertexData> list5 = list;
					List<int> list6 = list3;
					MeshFaceConnectivity meshFaceConnectivity3 = meshFaceConnectivity;
					MeshDataConnectivity meshDataConnectivity3 = meshDataConnectivity;
					Dictionary<EdgeKeyByIndex, ClippedEdge> dictionary7 = dictionary3;
					Dictionary<int, int> dictionary8 = dictionary5;
					int num4 = meshDataIn.aaIndices[i][j * 3];
					int num5 = meshDataIn.aaIndices[i][j * 3 + 1];
					int num6 = meshDataIn.aaIndices[i][j * 3 + 2];
					int nVertexHash = meshDataIn.aVertexData[num4].nVertexHash;
					int nVertexHash2 = meshDataIn.aVertexData[num5].nVertexHash;
					int nVertexHash3 = meshDataIn.aVertexData[num6].nVertexHash;
					Vector3 v3Vertex = meshDataIn.aVertexData[num4].v3Vertex;
					Vector3 v3Vertex2 = meshDataIn.aVertexData[num5].v3Vertex;
					Vector3 v3Vertex3 = meshDataIn.aVertexData[num6].v3Vertex;
					float num7 = v3Vertex.x * planeSplit.normal.x + v3Vertex.y * planeSplit.normal.y + v3Vertex.z * planeSplit.normal.z + planeSplit.distance;
					float num8 = v3Vertex2.x * planeSplit.normal.x + v3Vertex2.y * planeSplit.normal.y + v3Vertex2.z * planeSplit.normal.z + planeSplit.distance;
					float num9 = v3Vertex3.x * planeSplit.normal.x + v3Vertex3.y * planeSplit.normal.y + v3Vertex3.z * planeSplit.normal.z + planeSplit.distance;
					bool flag2 = false;
					int num10 = 0;
					bool flag3 = false;
					bool flag4 = false;
					bool flag5 = false;
					float num11 = 0f;
					if (Mathf.Abs(num7) < Parameters.EPSILONDISTANCEPLANE)
					{
						flag3 = true;
						num10++;
					}
					if (Mathf.Abs(num8) < Parameters.EPSILONDISTANCEPLANE)
					{
						flag4 = true;
						num10++;
					}
					if (Mathf.Abs(num9) < Parameters.EPSILONDISTANCEPLANE)
					{
						flag5 = true;
						num10++;
					}
					if (Mathf.Abs(num7) > Mathf.Abs(num11))
					{
						num11 = num7;
					}
					if (Mathf.Abs(num8) > Mathf.Abs(num11))
					{
						num11 = num8;
					}
					if (Mathf.Abs(num9) > Mathf.Abs(num11))
					{
						num11 = num9;
					}
					if (num10 == 1)
					{
						if (flag3 && num8 * num9 > 0f)
						{
							flag2 = true;
						}
						if (flag4 && num7 * num9 > 0f)
						{
							flag2 = true;
						}
						if (flag5 && num7 * num8 > 0f)
						{
							flag2 = true;
						}
						goto IL_45C;
					}
					if (num10 <= 1)
					{
						goto IL_45C;
					}
					flag2 = true;
					if (num10 != 3)
					{
						goto IL_45C;
					}
					IL_2B5E:
					j++;
					continue;
					IL_45C:
					if ((num7 * num8 > 0f && num8 * num9 > 0f) || flag2)
					{
						if (num11 < 0f)
						{
							list5 = list2;
							list6 = list4;
							meshFaceConnectivity3 = meshFaceConnectivity2;
							meshDataConnectivity3 = meshDataConnectivity2;
							dictionary8 = dictionary6;
						}
						int num12 = -1;
						int num13 = -1;
						int num14 = -1;
						if (dictionary8.ContainsKey(num4))
						{
							num12 = dictionary8[num4];
						}
						if (num12 == -1)
						{
							num12 = list5.Count;
							list5.Add(meshDataIn.aVertexData[num4].Copy());
							dictionary8[num4] = num12;
						}
						if (dictionary8.ContainsKey(num5))
						{
							num13 = dictionary8[num5];
						}
						if (num13 == -1)
						{
							num13 = list5.Count;
							list5.Add(meshDataIn.aVertexData[num5].Copy());
							dictionary8[num5] = num13;
						}
						if (dictionary8.ContainsKey(num6))
						{
							num14 = dictionary8[num6];
						}
						if (num14 == -1)
						{
							num14 = list5.Count;
							list5.Add(meshDataIn.aVertexData[num6].Copy());
							dictionary8[num6] = num14;
						}
						if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
						{
							meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
						}
						list6.Add(num12);
						list6.Add(num13);
						list6.Add(num14);
						if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
						{
							meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex2, nVertexHash, nVertexHash2, num12, num13);
							meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex3, nVertexHash2, nVertexHash3, num13, num14);
							meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex, nVertexHash3, nVertexHash, num14, num12);
						}
						if (num10 == 2)
						{
							if (num11 > 0f)
							{
								if (flag3 && flag4 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash, nVertexHash2, v3Vertex, v3Vertex2);
								}
								if (flag4 && flag5 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash2, nVertexHash3, v3Vertex2, v3Vertex3);
								}
								if (flag5 && flag3 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash3, nVertexHash, v3Vertex3, v3Vertex);
								}
							}
							else
							{
								if (flag3 && flag4 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash2, nVertexHash, v3Vertex2, v3Vertex);
								}
								if (flag4 && flag5 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash3, nVertexHash2, v3Vertex3, v3Vertex2);
								}
								if (flag5 && flag3 && !splitOptions.bForceNoCap)
								{
									Fracturer.AddCapEdge(dictionary2, nVertexHash, nVertexHash3, v3Vertex, v3Vertex3);
								}
							}
						}
						goto IL_2B5E;
					}
					if (num10 == 1)
					{
						int num15 = -1;
						int num16 = -1;
						int num17 = -1;
						int num18 = -1;
						bool flag6 = false;
						if (flag3)
						{
							if (num8 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							EdgeKeyByIndex key = new EdgeKeyByIndex(num5, num6);
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num16 = dictionary7[key].GetFirstIndex(num5);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num5))
								{
									num16 = dictionary8[num5];
								}
							}
							EdgeKeyByHash key2 = new EdgeKeyByHash(nVertexHash2, nVertexHash3);
							int num19;
							if (dictionary.ContainsKey(key2))
							{
								num19 = dictionary[key2];
							}
							else
							{
								num19 = nCurrentVertexHash++;
								dictionary.Add(key2, num19);
							}
							VertexData item = new VertexData(num19);
							if (!flag6 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num5, num6, v3Vertex2, v3Vertex3, planeSplit, ref item))
							{
								return false;
							}
							if (num15 == -1 && dictionary8.ContainsKey(num4))
							{
								num15 = dictionary8[num4];
							}
							if (num15 == -1)
							{
								num15 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num15;
							}
							if (num16 == -1)
							{
								num16 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num16;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num15);
							list6.Add(num16);
							list6.Add(num18);
							Vector3 v3Vertex4 = list5[num18].v3Vertex;
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex2, nVertexHash, nVertexHash2, num15, num16);
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex4, nVertexHash2, num19, num16, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex4, v3Vertex, num19, nVertexHash, num18, num15);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num19, nVertexHash, list5[num18].v3Vertex, list5[num15].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num5, num6, num16, num17, num18));
							}
							if (num9 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							else
							{
								list5 = list;
								list6 = list3;
								meshFaceConnectivity3 = meshFaceConnectivity;
								meshDataConnectivity3 = meshDataConnectivity;
								dictionary7 = dictionary3;
								dictionary8 = dictionary5;
							}
							num15 = -1;
							num16 = -1;
							num17 = -1;
							num18 = -1;
							flag6 = false;
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num17 = dictionary7[key].GetSecondIndex(num6);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num6))
								{
									num17 = dictionary8[num6];
								}
							}
							if (num15 == -1 && dictionary8.ContainsKey(num4))
							{
								num15 = dictionary8[num4];
							}
							if (num15 == -1)
							{
								num15 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num15;
							}
							if (num17 == -1)
							{
								num17 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num17;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num15);
							list6.Add(num18);
							list6.Add(num17);
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex4, nVertexHash, num19, num15, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex4, v3Vertex3, num19, nVertexHash3, num18, num17);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex, nVertexHash3, nVertexHash, num17, num15);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, nVertexHash, num19, list5[num15].v3Vertex, list5[num18].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num5, num6, num16, num17, num18));
							}
						}
						else if (flag4)
						{
							if (num9 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							EdgeKeyByIndex key = new EdgeKeyByIndex(num6, num4);
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num17 = dictionary7[key].GetFirstIndex(num6);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num6))
								{
									num17 = dictionary8[num6];
								}
							}
							EdgeKeyByHash key3 = new EdgeKeyByHash(nVertexHash3, nVertexHash);
							int num19;
							if (dictionary.ContainsKey(key3))
							{
								num19 = dictionary[key3];
							}
							else
							{
								num19 = nCurrentVertexHash++;
								dictionary.Add(key3, num19);
							}
							VertexData item2 = new VertexData(num19);
							if (!flag6 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num6, num4, v3Vertex3, v3Vertex, planeSplit, ref item2))
							{
								return false;
							}
							if (num16 == -1 && dictionary8.ContainsKey(num5))
							{
								num16 = dictionary8[num5];
							}
							if (num16 == -1)
							{
								num16 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num16;
							}
							if (num17 == -1)
							{
								num17 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num17;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item2);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num16);
							list6.Add(num17);
							list6.Add(num18);
							Vector3 v3Vertex5 = list5[num18].v3Vertex;
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex3, nVertexHash2, nVertexHash3, num16, num17);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex5, nVertexHash3, num19, num17, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex5, v3Vertex2, num19, nVertexHash2, num18, num16);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num19, nVertexHash2, list5[num18].v3Vertex, list5[num16].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num6, num4, num17, num15, num18));
							}
							if (num7 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							else
							{
								list5 = list;
								list6 = list3;
								meshFaceConnectivity3 = meshFaceConnectivity;
								meshDataConnectivity3 = meshDataConnectivity;
								dictionary7 = dictionary3;
								dictionary8 = dictionary5;
							}
							num15 = -1;
							num16 = -1;
							num18 = -1;
							flag6 = false;
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num15 = dictionary7[key].GetSecondIndex(num4);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num4))
								{
									num15 = dictionary8[num4];
								}
							}
							if (num15 == -1)
							{
								num15 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num15;
							}
							if (num16 == -1 && dictionary8.ContainsKey(num5))
							{
								num16 = dictionary8[num5];
							}
							if (num16 == -1)
							{
								num16 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num16;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item2);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num16);
							list6.Add(num18);
							list6.Add(num15);
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex5, nVertexHash2, num19, num16, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex5, v3Vertex, num19, nVertexHash, num18, num15);
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex2, nVertexHash, nVertexHash2, num15, num16);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, nVertexHash2, num19, list5[num16].v3Vertex, list5[num18].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num6, num4, num17, num15, num18));
							}
						}
						else if (flag5)
						{
							if (num7 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							EdgeKeyByIndex key = new EdgeKeyByIndex(num4, num5);
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num15 = dictionary7[key].GetFirstIndex(num4);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num4))
								{
									num15 = dictionary8[num4];
								}
							}
							EdgeKeyByHash key4 = new EdgeKeyByHash(nVertexHash, nVertexHash2);
							int num19;
							if (dictionary.ContainsKey(key4))
							{
								num19 = dictionary[key4];
							}
							else
							{
								num19 = nCurrentVertexHash++;
								dictionary.Add(key4, num19);
							}
							VertexData item3 = new VertexData(num19);
							if (!flag6 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num4, num5, v3Vertex, v3Vertex2, planeSplit, ref item3))
							{
								return false;
							}
							if (num15 == -1)
							{
								num15 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num15;
							}
							if (num17 == -1 && dictionary8.ContainsKey(num6))
							{
								num17 = dictionary8[num6];
							}
							if (num17 == -1)
							{
								num17 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num17;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item3);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num15);
							list6.Add(num18);
							list6.Add(num17);
							Vector3 v3Vertex6 = list5[num18].v3Vertex;
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex6, nVertexHash, num19, num15, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex6, v3Vertex3, num19, nVertexHash3, num18, num17);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex, nVertexHash3, nVertexHash, num17, num15);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num19, nVertexHash3, list5[num18].v3Vertex, list5[num17].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num4, num5, num15, num16, num18));
							}
							if (num8 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							else
							{
								list5 = list;
								list6 = list3;
								meshFaceConnectivity3 = meshFaceConnectivity;
								meshDataConnectivity3 = meshDataConnectivity;
								dictionary7 = dictionary3;
								dictionary8 = dictionary5;
							}
							num16 = -1;
							num17 = -1;
							num18 = -1;
							flag6 = false;
							if (dictionary7.ContainsKey(key))
							{
								num2++;
								flag6 = true;
								num16 = dictionary7[key].GetSecondIndex(num5);
								num18 = dictionary7[key].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num5))
								{
									num16 = dictionary8[num5];
								}
							}
							if (num16 == -1)
							{
								num16 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num16;
							}
							if (num17 == -1 && dictionary8.ContainsKey(num6))
							{
								num17 = dictionary8[num6];
							}
							if (num17 == -1)
							{
								num17 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num17;
							}
							if (num18 == -1)
							{
								num18 = list5.Count;
								list5.Add(item3);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num16);
							list6.Add(num17);
							list6.Add(num18);
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex3, nVertexHash2, nVertexHash3, num16, num17);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex6, nVertexHash3, num19, num17, num18);
								meshFaceConnectivity3.AddEdge(i, v3Vertex6, v3Vertex2, num19, nVertexHash2, num18, num16);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, nVertexHash3, num19, list5[num17].v3Vertex, list5[num18].v3Vertex);
							}
							if (!flag6)
							{
								dictionary7.Add(key, new ClippedEdge(num4, num5, num15, num16, num18));
							}
						}
						goto IL_2B5E;
					}
					if (num7 * num8 < 0f)
					{
						if (num8 * num9 < 0f)
						{
							if (num7 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							int num20 = -1;
							int num21 = -1;
							int num22 = -1;
							int num23 = -1;
							int num24 = -1;
							bool flag7 = false;
							bool flag8 = false;
							EdgeKeyByIndex key5 = new EdgeKeyByIndex(num4, num5);
							EdgeKeyByIndex key6 = new EdgeKeyByIndex(num5, num6);
							if (dictionary7.ContainsKey(key5))
							{
								num2++;
								flag7 = true;
								num20 = dictionary7[key5].GetFirstIndex(num4);
								num23 = dictionary7[key5].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num4))
								{
									num20 = dictionary8[num4];
								}
							}
							if (dictionary7.ContainsKey(key6))
							{
								num2++;
								flag8 = true;
								num22 = dictionary7[key6].GetSecondIndex(num6);
								num24 = dictionary7[key6].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num6))
								{
									num22 = dictionary8[num6];
								}
							}
							EdgeKeyByHash key7 = new EdgeKeyByHash(nVertexHash, nVertexHash2);
							int num25;
							if (dictionary.ContainsKey(key7))
							{
								num25 = dictionary[key7];
							}
							else
							{
								num25 = nCurrentVertexHash++;
								dictionary.Add(key7, num25);
							}
							key7 = new EdgeKeyByHash(nVertexHash2, nVertexHash3);
							int num26;
							if (dictionary.ContainsKey(key7))
							{
								num26 = dictionary[key7];
							}
							else
							{
								num26 = nCurrentVertexHash++;
								dictionary.Add(key7, num26);
							}
							VertexData item4 = new VertexData(num25);
							VertexData item5 = new VertexData(num26);
							if (!flag7 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num4, num5, v3Vertex, v3Vertex2, planeSplit, ref item4))
							{
								return false;
							}
							if (!flag8 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num5, num6, v3Vertex2, v3Vertex3, planeSplit, ref item5))
							{
								return false;
							}
							if (num20 == -1)
							{
								num20 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num20;
							}
							if (num22 == -1)
							{
								num22 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num22;
							}
							if (num23 == -1)
							{
								num23 = list5.Count;
								list5.Add(item4);
							}
							if (num24 == -1)
							{
								num24 = list5.Count;
								list5.Add(item5);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num20);
							list6.Add(num23);
							list6.Add(num24);
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num20);
							list6.Add(num24);
							list6.Add(num22);
							Vector3 v3Vertex7 = list5[num23].v3Vertex;
							Vector3 v3Vertex8 = list5[num24].v3Vertex;
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex7, nVertexHash, num25, num20, num23);
								meshFaceConnectivity3.AddEdge(i, v3Vertex7, v3Vertex8, num25, num26, num23, num24);
								meshFaceConnectivity3.AddEdge(i, v3Vertex8, v3Vertex, num26, nVertexHash, num24, num20);
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex8, nVertexHash, num26, num20, num24);
								meshFaceConnectivity3.AddEdge(i, v3Vertex8, v3Vertex3, num26, nVertexHash3, num24, num22);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex, nVertexHash3, nVertexHash, num22, num20);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num25, num26, list5[num23].v3Vertex, list5[num24].v3Vertex);
							}
							if (!dictionary7.ContainsKey(key5))
							{
								dictionary7.Add(key5, new ClippedEdge(num4, num5, num20, num21, num23));
							}
							if (!dictionary7.ContainsKey(key6))
							{
								dictionary7.Add(key6, new ClippedEdge(num5, num6, num21, num22, num24));
							}
							if (num8 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							else
							{
								list5 = list;
								list6 = list3;
								meshFaceConnectivity3 = meshFaceConnectivity;
								meshDataConnectivity3 = meshDataConnectivity;
								dictionary7 = dictionary3;
								dictionary8 = dictionary5;
							}
							num20 = -1;
							num21 = -1;
							num22 = -1;
							num23 = -1;
							num24 = -1;
							if (dictionary7.ContainsKey(key5))
							{
								num2++;
								num21 = dictionary7[key5].GetSecondIndex(num5);
								num23 = dictionary7[key5].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num5))
								{
									num21 = dictionary8[num5];
								}
							}
							if (dictionary7.ContainsKey(key6))
							{
								num2++;
								num21 = dictionary7[key6].GetFirstIndex(num5);
								num24 = dictionary7[key6].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num5))
								{
									num21 = dictionary8[num5];
								}
							}
							if (num21 == -1)
							{
								num21 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num21;
							}
							if (num23 == -1)
							{
								num23 = list5.Count;
								list5.Add(item4);
							}
							if (num24 == -1)
							{
								num24 = list5.Count;
								list5.Add(item5);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num23);
							list6.Add(num21);
							list6.Add(num24);
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex7, v3Vertex2, num25, nVertexHash2, num23, num21);
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex8, nVertexHash2, num26, num21, num24);
								meshFaceConnectivity3.AddEdge(i, v3Vertex8, v3Vertex7, num26, num25, num24, num23);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num26, num25, list5[num24].v3Vertex, list5[num23].v3Vertex);
							}
							if (!dictionary7.ContainsKey(key5))
							{
								dictionary7.Add(key5, new ClippedEdge(num4, num5, num20, num21, num23));
							}
							if (!dictionary7.ContainsKey(key6))
							{
								dictionary7.Add(key6, new ClippedEdge(num5, num6, num21, num22, num24));
							}
						}
						else
						{
							if (num7 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							int num27 = -1;
							int num28 = -1;
							int num29 = -1;
							int num30 = -1;
							int num31 = -1;
							bool flag9 = false;
							bool flag10 = false;
							EdgeKeyByIndex key8 = new EdgeKeyByIndex(num4, num5);
							EdgeKeyByIndex key9 = new EdgeKeyByIndex(num4, num6);
							if (dictionary7.ContainsKey(key8))
							{
								num2++;
								flag9 = true;
								num27 = dictionary7[key8].GetFirstIndex(num4);
								num30 = dictionary7[key8].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num4))
								{
									num27 = dictionary8[num4];
								}
							}
							if (dictionary7.ContainsKey(key9))
							{
								num2++;
								flag10 = true;
								num27 = dictionary7[key9].GetFirstIndex(num4);
								num31 = dictionary7[key9].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num4))
								{
									num27 = dictionary8[num4];
								}
							}
							EdgeKeyByHash key10 = new EdgeKeyByHash(nVertexHash, nVertexHash2);
							int num32;
							if (dictionary.ContainsKey(key10))
							{
								num32 = dictionary[key10];
							}
							else
							{
								num32 = nCurrentVertexHash++;
								dictionary.Add(key10, num32);
							}
							key10 = new EdgeKeyByHash(nVertexHash, nVertexHash3);
							int num33;
							if (dictionary.ContainsKey(key10))
							{
								num33 = dictionary[key10];
							}
							else
							{
								num33 = nCurrentVertexHash++;
								dictionary.Add(key10, num33);
							}
							VertexData item6 = new VertexData(num32);
							VertexData item7 = new VertexData(num33);
							if (!flag9 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num4, num5, v3Vertex, v3Vertex2, planeSplit, ref item6))
							{
								return false;
							}
							if (!flag10 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num4, num6, v3Vertex, v3Vertex3, planeSplit, ref item7))
							{
								return false;
							}
							if (num27 == -1)
							{
								num27 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num4].Copy());
								dictionary8[num4] = num27;
							}
							if (num30 == -1)
							{
								num30 = list5.Count;
								list5.Add(item6);
							}
							if (num31 == -1)
							{
								num31 = list5.Count;
								list5.Add(item7);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num27);
							list6.Add(num30);
							list6.Add(num31);
							Vector3 v3Vertex9 = list5[num30].v3Vertex;
							Vector3 v3Vertex10 = list5[num31].v3Vertex;
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex9, nVertexHash, num32, num27, num30);
								meshFaceConnectivity3.AddEdge(i, v3Vertex9, v3Vertex10, num32, num33, num30, num31);
								meshFaceConnectivity3.AddEdge(i, v3Vertex10, v3Vertex, num33, nVertexHash, num31, num27);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num32, num33, list5[num30].v3Vertex, list5[num31].v3Vertex);
							}
							if (!dictionary7.ContainsKey(key8))
							{
								dictionary7.Add(key8, new ClippedEdge(num4, num5, num27, num28, num30));
							}
							if (!dictionary7.ContainsKey(key9))
							{
								dictionary7.Add(key9, new ClippedEdge(num4, num6, num27, num29, num31));
							}
							if (num8 < 0f)
							{
								list5 = list2;
								list6 = list4;
								meshFaceConnectivity3 = meshFaceConnectivity2;
								meshDataConnectivity3 = meshDataConnectivity2;
								dictionary7 = dictionary4;
								dictionary8 = dictionary6;
							}
							else
							{
								list5 = list;
								list6 = list3;
								meshFaceConnectivity3 = meshFaceConnectivity;
								meshDataConnectivity3 = meshDataConnectivity;
								dictionary7 = dictionary3;
								dictionary8 = dictionary5;
							}
							num27 = -1;
							num28 = -1;
							num29 = -1;
							num30 = -1;
							num31 = -1;
							if (dictionary7.ContainsKey(key8))
							{
								num2++;
								num28 = dictionary7[key8].GetSecondIndex(num5);
								num30 = dictionary7[key8].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num5))
								{
									num28 = dictionary8[num5];
								}
							}
							if (dictionary7.ContainsKey(key9))
							{
								num2++;
								num29 = dictionary7[key9].GetSecondIndex(num6);
								num31 = dictionary7[key9].nClippedIndex;
							}
							else
							{
								num3++;
								if (dictionary8.ContainsKey(num6))
								{
									num29 = dictionary8[num6];
								}
							}
							if (num28 == -1)
							{
								num28 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num5].Copy());
								dictionary8[num5] = num28;
							}
							if (num29 == -1)
							{
								num29 = list5.Count;
								list5.Add(meshDataIn.aVertexData[num6].Copy());
								dictionary8[num6] = num29;
							}
							if (num30 == -1)
							{
								num30 = list5.Count;
								list5.Add(item6);
							}
							if (num31 == -1)
							{
								num31 = list5.Count;
								list5.Add(item7);
							}
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num30);
							list6.Add(num28);
							list6.Add(num29);
							if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
							{
								meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
							}
							list6.Add(num30);
							list6.Add(num29);
							list6.Add(num31);
							if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
							{
								meshFaceConnectivity3.AddEdge(i, v3Vertex9, v3Vertex2, num32, nVertexHash2, num30, num28);
								meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex3, nVertexHash2, nVertexHash3, num28, num29);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex9, nVertexHash3, num32, num29, num30);
								meshFaceConnectivity3.AddEdge(i, v3Vertex9, v3Vertex3, num32, nVertexHash3, num30, num29);
								meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex10, nVertexHash3, num33, num29, num31);
								meshFaceConnectivity3.AddEdge(i, v3Vertex10, v3Vertex9, num33, num32, num31, num30);
							}
							if (list5 == list && !splitOptions.bForceNoCap)
							{
								Fracturer.AddCapEdge(dictionary2, num33, num32, list5[num31].v3Vertex, list5[num30].v3Vertex);
							}
							if (!dictionary7.ContainsKey(key8))
							{
								dictionary7.Add(key8, new ClippedEdge(num4, num5, num27, num28, num30));
							}
							if (!dictionary7.ContainsKey(key9))
							{
								dictionary7.Add(key9, new ClippedEdge(num4, num6, num27, num29, num31));
							}
						}
						goto IL_2B5E;
					}
					if (num8 * num9 >= 0f)
					{
						goto IL_2B5E;
					}
					if (num7 < 0f)
					{
						list5 = list2;
						list6 = list4;
						meshFaceConnectivity3 = meshFaceConnectivity2;
						meshDataConnectivity3 = meshDataConnectivity2;
						dictionary7 = dictionary4;
						dictionary8 = dictionary6;
					}
					int num34 = -1;
					int num35 = -1;
					int num36 = -1;
					int num37 = -1;
					int num38 = -1;
					bool flag11 = false;
					bool flag12 = false;
					EdgeKeyByIndex key11 = new EdgeKeyByIndex(num5, num6);
					EdgeKeyByIndex key12 = new EdgeKeyByIndex(num4, num6);
					if (dictionary7.ContainsKey(key11))
					{
						num2++;
						flag11 = true;
						num35 = dictionary7[key11].GetFirstIndex(num5);
						num38 = dictionary7[key11].nClippedIndex;
					}
					else
					{
						num3++;
						if (dictionary8.ContainsKey(num5))
						{
							num35 = dictionary8[num5];
						}
					}
					if (dictionary7.ContainsKey(key12))
					{
						num2++;
						flag12 = true;
						num34 = dictionary7[key12].GetFirstIndex(num4);
						num37 = dictionary7[key12].nClippedIndex;
					}
					else
					{
						num3++;
						if (dictionary8.ContainsKey(num4))
						{
							num34 = dictionary8[num4];
						}
					}
					EdgeKeyByHash key13 = new EdgeKeyByHash(nVertexHash, nVertexHash3);
					int num39;
					if (dictionary.ContainsKey(key13))
					{
						num39 = dictionary[key13];
					}
					else
					{
						num39 = nCurrentVertexHash++;
						dictionary.Add(key13, num39);
					}
					key13 = new EdgeKeyByHash(nVertexHash2, nVertexHash3);
					int num40;
					if (dictionary.ContainsKey(key13))
					{
						num40 = dictionary[key13];
					}
					else
					{
						num40 = nCurrentVertexHash++;
						dictionary.Add(key13, num40);
					}
					VertexData item8 = new VertexData(num39);
					VertexData item9 = new VertexData(num40);
					if (!flag11 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num5, num6, v3Vertex2, v3Vertex3, planeSplit, ref item9))
					{
						return false;
					}
					if (!flag12 && !VertexData.ClipAgainstPlane(meshDataIn.aVertexData, num4, num6, v3Vertex, v3Vertex3, planeSplit, ref item8))
					{
						return false;
					}
					if (num34 == -1)
					{
						num34 = list5.Count;
						list5.Add(meshDataIn.aVertexData[num4].Copy());
						dictionary8[num4] = num34;
					}
					if (num35 == -1)
					{
						num35 = list5.Count;
						list5.Add(meshDataIn.aVertexData[num5].Copy());
						dictionary8[num5] = num35;
					}
					if (num37 == -1)
					{
						num37 = list5.Count;
						list5.Add(item8);
					}
					if (num38 == -1)
					{
						num38 = list5.Count;
						list5.Add(item9);
					}
					if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
					{
						meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
					}
					list6.Add(num35);
					list6.Add(num38);
					list6.Add(num37);
					if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
					{
						meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
					}
					list6.Add(num35);
					list6.Add(num37);
					list6.Add(num34);
					Vector3 v3Vertex11 = list5[num37].v3Vertex;
					Vector3 v3Vertex12 = list5[num38].v3Vertex;
					if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
					{
						meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex12, nVertexHash2, num40, num35, num38);
						meshFaceConnectivity3.AddEdge(i, v3Vertex12, v3Vertex11, num40, num39, num38, num37);
						meshFaceConnectivity3.AddEdge(i, v3Vertex11, v3Vertex2, num39, nVertexHash2, num37, num35);
						meshFaceConnectivity3.AddEdge(i, v3Vertex2, v3Vertex11, nVertexHash2, num39, num35, num37);
						meshFaceConnectivity3.AddEdge(i, v3Vertex11, v3Vertex, num39, nVertexHash, num37, num34);
						meshFaceConnectivity3.AddEdge(i, v3Vertex, v3Vertex2, nVertexHash, nVertexHash2, num34, num35);
					}
					if (list5 == list && !splitOptions.bForceNoCap)
					{
						Fracturer.AddCapEdge(dictionary2, num40, num39, list5[num38].v3Vertex, list5[num37].v3Vertex);
					}
					if (!dictionary7.ContainsKey(key11))
					{
						dictionary7.Add(key11, new ClippedEdge(num5, num6, num35, num36, num38));
					}
					if (!dictionary7.ContainsKey(key12))
					{
						dictionary7.Add(key12, new ClippedEdge(num4, num6, num34, num36, num37));
					}
					if (num9 < 0f)
					{
						list5 = list2;
						list6 = list4;
						meshFaceConnectivity3 = meshFaceConnectivity2;
						meshDataConnectivity3 = meshDataConnectivity2;
						dictionary7 = dictionary4;
						dictionary8 = dictionary6;
					}
					else
					{
						list5 = list;
						list6 = list3;
						meshFaceConnectivity3 = meshFaceConnectivity;
						meshDataConnectivity3 = meshDataConnectivity;
						dictionary7 = dictionary3;
						dictionary8 = dictionary5;
					}
					num34 = -1;
					num35 = -1;
					num36 = -1;
					num37 = -1;
					num38 = -1;
					if (dictionary7.ContainsKey(key11))
					{
						num2++;
						num36 = dictionary7[key11].GetSecondIndex(num6);
						num38 = dictionary7[key11].nClippedIndex;
					}
					else
					{
						num3++;
						if (dictionary8.ContainsKey(num6))
						{
							num36 = dictionary8[num6];
						}
					}
					if (dictionary7.ContainsKey(key12))
					{
						num2++;
						num36 = dictionary7[key12].GetSecondIndex(num6);
						num37 = dictionary7[key12].nClippedIndex;
					}
					else
					{
						num3++;
						if (dictionary8.ContainsKey(num6))
						{
							num36 = dictionary8[num6];
						}
					}
					if (num36 == -1)
					{
						num36 = list5.Count;
						list5.Add(meshDataIn.aVertexData[num6].Copy());
						dictionary8[num6] = num36;
					}
					if (num37 == -1)
					{
						num37 = list5.Count;
						list5.Add(item8);
					}
					if (num38 == -1)
					{
						num38 = list5.Count;
						list5.Add(item9);
					}
					if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoChunkConnectionInfo)
					{
						meshDataConnectivity3.NotifyNewClippedFace(meshDataIn, i, j, i, list6.Count / 3);
					}
					list6.Add(num38);
					list6.Add(num36);
					list6.Add(num37);
					if (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration)
					{
						meshFaceConnectivity3.AddEdge(i, v3Vertex12, v3Vertex3, num40, nVertexHash3, num38, num36);
						meshFaceConnectivity3.AddEdge(i, v3Vertex3, v3Vertex11, nVertexHash3, num39, num36, num37);
						meshFaceConnectivity3.AddEdge(i, v3Vertex11, v3Vertex12, num39, num40, num37, num38);
					}
					if (list5 == list && !splitOptions.bForceNoCap)
					{
						Fracturer.AddCapEdge(dictionary2, num39, num40, list5[num37].v3Vertex, list5[num38].v3Vertex);
					}
					if (!dictionary7.ContainsKey(key11))
					{
						dictionary7.Add(key11, new ClippedEdge(num5, num6, num35, num36, num38));
					}
					if (!dictionary7.ContainsKey(key12))
					{
						dictionary7.Add(key12, new ClippedEdge(num4, num6, num34, num36, num37));
						goto IL_2B5E;
					}
					goto IL_2B5E;
				}
			}
			Vector3 vector = Vector3.zero;
			if (list.Count > 0)
			{
				Vector3 zero = Vector3.zero;
				Vector3 zero2 = Vector3.zero;
				MeshData.ComputeMinMax(list, ref zero, ref zero2);
				vector = (zero + zero2) * 0.5f;
			}
			Matrix4x4 inverse = Matrix4x4.TRS(vector, meshDataIn.qRotation, meshDataIn.v3Scale).inverse;
			if (splitOptions.bVerticesAreLocal)
			{
				inverse = Matrix4x4.TRS(vector, Quaternion.identity, Vector3.one).inverse;
			}
			Vector3 vector2 = Vector3.zero;
			if (list2.Count > 0)
			{
				Vector3 zero3 = Vector3.zero;
				Vector3 zero4 = Vector3.zero;
				MeshData.ComputeMinMax(list2, ref zero3, ref zero4);
				vector2 = (zero3 + zero4) * 0.5f;
			}
			Matrix4x4 inverse2 = Matrix4x4.TRS(vector2, meshDataIn.qRotation, meshDataIn.v3Scale).inverse;
			if (splitOptions.bVerticesAreLocal)
			{
				inverse2 = Matrix4x4.TRS(vector2, Quaternion.identity, Vector3.one).inverse;
			}
			List<List<Vector3>> list7 = new List<List<Vector3>>();
			List<List<int>> list8 = new List<List<int>>();
			bool flag13 = false;
			Matrix4x4 mtxPlane = Matrix4x4.TRS(v3PlanePoint, Quaternion.LookRotation(Vector3.Cross(v3PlaneNormal, v3PlaneRight), v3PlaneNormal), Vector3.one);
			if (dictionary2.Count > 0 && !splitOptions.bForceNoCap)
			{
				if (Fracturer.ResolveCap(dictionary2, list7, list8, fracturedComponent))
				{
					if (list7.Count > 1)
					{
						flag13 = (fracturedComponent.GenerateIslands && !splitOptions.bForceNoIslandGeneration);
					}
					Fracturer.TriangulateConstrainedDelaunay(list7, list8, splitOptions.bForceCapVertexSoup, fracturedComponent, flag13, meshFaceConnectivity, meshFaceConnectivity2, meshDataConnectivity, meshDataConnectivity2, splitOptions.nForceMeshConnectivityHash, num, mtxPlane, inverse, inverse2, vector, vector2, array, list, array2, list2);
				}
				else if (fracturedComponent.Verbose)
				{
					Debug.LogWarning("Error resolving cap");
				}
			}
			if (flag13)
			{
				List<MeshData> collection = MeshData.PostProcessConnectivity(meshDataIn, meshFaceConnectivity, meshDataConnectivity, array, list, num, nCurrentVertexHash, false);
				List<MeshData> collection2 = new List<MeshData>();
				if (!splitOptions.bIgnoreNegativeSide)
				{
					collection2 = MeshData.PostProcessConnectivity(meshDataIn, meshFaceConnectivity2, meshDataConnectivity2, array2, list2, num, nCurrentVertexHash, false);
				}
				List<MeshData> list9 = new List<MeshData>();
				list9.AddRange(collection);
				list9.AddRange(collection2);
				if (fracturedComponent.GenerateChunkConnectionInfo && !splitOptions.bForceNoIslandConnectionInfo)
				{
					for (int k = 0; k < list9.Count; k++)
					{
						if (progress != null && list9.Count > 10 && !splitOptions.bForceNoProgressInfo)
						{
							progress("Fracturing", "Processing island connectivity...", (float)k / (float)list9.Count);
							if (Fracturer.IsFracturingCancelled())
							{
								return false;
							}
						}
						for (int l = 0; l < list9.Count; l++)
						{
							if (k != l)
							{
								Fracturer.ComputeIslandsMeshDataConnectivity(fracturedComponent, splitOptions.bVerticesAreLocal, list9[k], list9[l]);
							}
						}
					}
				}
				listMeshDatasPosOut.AddRange(collection);
				listMeshDatasNegOut.AddRange(collection2);
			}
			else
			{
				if (list.Count > 0 && array.Length > 0)
				{
					MeshData meshData = new MeshData(meshDataIn.aMaterials, array, list, num, vector, meshDataIn.qRotation, meshDataIn.v3Scale, inverse, false, false);
					meshData.meshDataConnectivity = meshDataConnectivity;
					meshData.nCurrentVertexHash = nCurrentVertexHash;
					listMeshDatasPosOut.Add(meshData);
				}
				if (list2.Count > 0 && array2.Length > 0 && !splitOptions.bIgnoreNegativeSide)
				{
					MeshData meshData2 = new MeshData(meshDataIn.aMaterials, array2, list2, num, vector2, meshDataIn.qRotation, meshDataIn.v3Scale, inverse2, false, false);
					meshData2.meshDataConnectivity = meshDataConnectivity2;
					meshData2.nCurrentVertexHash = nCurrentVertexHash;
					listMeshDatasNegOut.Add(meshData2);
				}
			}
			return true;
		}

		// Token: 0x06001DF9 RID: 7673 RVA: 0x000BC79C File Offset: 0x000BA99C
		private static bool ComputeIslandsMeshDataConnectivity(FracturedObject fracturedComponent, bool bVerticesAreLocal, MeshData meshData1, MeshData meshData2)
		{
			float chunkIslandConnectionMaxDistance = fracturedComponent.ChunkIslandConnectionMaxDistance;
			Vector3 a = meshData1.v3Min;
			if (bVerticesAreLocal)
			{
				a = Vector3.Scale(a, meshData1.v3Scale);
			}
			Vector3 a2 = meshData1.v3Max;
			if (bVerticesAreLocal)
			{
				a2 = Vector3.Scale(a2, meshData1.v3Scale);
			}
			Vector3 a3 = meshData2.v3Min;
			if (bVerticesAreLocal)
			{
				a3 = Vector3.Scale(a3, meshData2.v3Scale);
			}
			Vector3 a4 = meshData2.v3Max;
			if (bVerticesAreLocal)
			{
				a4 = Vector3.Scale(a4, meshData2.v3Scale);
			}
			if (a.x > a4.x + chunkIslandConnectionMaxDistance || a.y > a4.y + chunkIslandConnectionMaxDistance || a.z > a4.z + chunkIslandConnectionMaxDistance)
			{
				return false;
			}
			if (a3.x > a2.x + chunkIslandConnectionMaxDistance || a3.y > a2.y + chunkIslandConnectionMaxDistance || a3.z > a2.z + chunkIslandConnectionMaxDistance)
			{
				return false;
			}
			bool result = false;
			float chunkIslandConnectionMaxDistance2 = fracturedComponent.ChunkIslandConnectionMaxDistance;
			for (int i = 0; i < meshData1.aaIndices.Length; i++)
			{
				for (int j = 0; j < meshData1.aaIndices[i].Length / 3; j++)
				{
					Vector3 vector = meshData1.aVertexData[meshData1.aaIndices[i][j * 3]].v3Vertex;
					Vector3 vector2 = meshData1.aVertexData[meshData1.aaIndices[i][j * 3 + 1]].v3Vertex;
					Vector3 vector3 = meshData1.aVertexData[meshData1.aaIndices[i][j * 3 + 2]].v3Vertex;
					if (bVerticesAreLocal)
					{
						vector = Vector3.Scale(vector, meshData1.v3Scale);
						vector2 = Vector3.Scale(vector2, meshData1.v3Scale);
						vector3 = Vector3.Scale(vector3, meshData1.v3Scale);
					}
					Vector3 vector4 = -Vector3.Cross(vector2 - vector, vector3 - vector);
					float magnitude = vector4.magnitude;
					if (magnitude >= Parameters.EPSILONCROSSPRODUCT)
					{
						Quaternion q = Quaternion.LookRotation(vector4.normalized, (vector2 - vector).normalized);
						Matrix4x4 inverse = Matrix4x4.TRS(vector, q, Vector3.one).inverse;
						Plane plane = new Plane(vector, vector2, vector3);
						for (int k = 0; k < meshData2.aaIndices.Length; k++)
						{
							for (int l = 0; l < meshData2.aaIndices[k].Length / 3; l++)
							{
								Vector3 vector5 = meshData2.aVertexData[meshData2.aaIndices[k][l * 3]].v3Vertex;
								Vector3 vector6 = meshData2.aVertexData[meshData2.aaIndices[k][l * 3 + 1]].v3Vertex;
								Vector3 vector7 = meshData2.aVertexData[meshData2.aaIndices[k][l * 3 + 2]].v3Vertex;
								if (bVerticesAreLocal)
								{
									vector5 = Vector3.Scale(vector5, meshData2.v3Scale);
									vector6 = Vector3.Scale(vector6, meshData2.v3Scale);
									vector7 = Vector3.Scale(vector7, meshData2.v3Scale);
								}
								float num = Mathf.Abs(plane.GetDistanceToPoint(vector5));
								if (num <= chunkIslandConnectionMaxDistance2)
								{
									float num2 = Mathf.Abs(plane.GetDistanceToPoint(vector6));
									if (num2 <= chunkIslandConnectionMaxDistance2)
									{
										float num3 = Mathf.Abs(plane.GetDistanceToPoint(vector7));
										if (num3 <= chunkIslandConnectionMaxDistance2)
										{
											Vector3 vector8 = (vector5 + vector6 + vector7) / 3f;
											vector8 = inverse.MultiplyPoint3x4(vector8);
											Vector3 a5 = inverse.MultiplyPoint3x4(vector);
											Vector3 b = inverse.MultiplyPoint3x4(vector2);
											Vector3 vector9 = inverse.MultiplyPoint3x4(vector3);
											Vector3 lhs = vector9 - b;
											Vector3 lhs2 = a5 - vector9;
											bool flag = false;
											if (vector8.x >= 0f && Vector3.Cross(lhs, vector8 - b).z <= 0f && Vector3.Cross(lhs2, vector8 - vector9).z <= 0f)
											{
												flag = true;
											}
											if (!flag)
											{
												Vector3 vector10 = inverse.MultiplyPoint3x4(vector5);
												Vector3 vector11 = inverse.MultiplyPoint3x4(vector6);
												Vector3 vector12 = inverse.MultiplyPoint3x4(vector7);
												if (!flag && Fracturer.IntersectEdges2D(vector10.x, vector10.y, vector11.x, vector11.y, a5.x, a5.y, b.x, b.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector10.x, vector10.y, vector11.x, vector11.y, b.x, b.y, vector9.x, vector9.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector10.x, vector10.y, vector11.x, vector11.y, vector9.x, vector9.y, a5.x, a5.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector11.x, vector11.y, vector12.x, vector12.y, a5.x, a5.y, b.x, b.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector11.x, vector11.y, vector12.x, vector12.y, b.x, b.y, vector9.x, vector9.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector11.x, vector11.y, vector12.x, vector12.y, vector9.x, vector9.y, a5.x, a5.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector12.x, vector12.y, vector10.x, vector10.y, a5.x, a5.y, b.x, b.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector12.x, vector12.y, vector10.x, vector10.y, b.x, b.y, vector9.x, vector9.y))
												{
													flag = true;
												}
												if (!flag && Fracturer.IntersectEdges2D(vector12.x, vector12.y, vector10.x, vector10.y, vector9.x, vector9.y, a5.x, a5.y))
												{
													flag = true;
												}
											}
											if (flag)
											{
												int newHash = MeshDataConnectivity.GetNewHash();
												meshData1.meshDataConnectivity.NotifyNewCapFace(newHash, i, j);
												meshData2.meshDataConnectivity.NotifyNewCapFace(newHash, k, l);
												result = true;
											}
										}
									}
								}
							}
						}
					}
				}
			}
			return result;
		}

		// Token: 0x06001DFA RID: 7674 RVA: 0x000BCED8 File Offset: 0x000BB0D8
		public static bool IntersectEdges2D(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
		{
			Vector2 b = new Vector2(x1, y1);
			Vector2 a = new Vector2(x3, y3);
			Vector2 vector = new Vector2(x2 - x1, y2 - y1);
			Vector2 b2 = new Vector2(x4 - x3, y4 - y3);
			float num = Fracturer.CrossProduct2D(vector, b2);
			if (num < Parameters.EPSILONCROSSPRODUCT)
			{
				return false;
			}
			float num2 = Fracturer.CrossProduct2D(a - b, b2) / num;
			float num3 = Fracturer.CrossProduct2D(a - b, vector) / num;
			float epsiloninsidetriangle = Parameters.EPSILONINSIDETRIANGLE;
			return num2 >= epsiloninsidetriangle && num2 <= 1f - epsiloninsidetriangle && num3 >= epsiloninsidetriangle && num3 <= 1f - epsiloninsidetriangle;
		}

		// Token: 0x06001DFB RID: 7675 RVA: 0x000BCF8C File Offset: 0x000BB18C
		private static float CrossProduct2D(Vector2 a, Vector2 b)
		{
			return a.x * b.y - a.y * b.x;
		}

		// Token: 0x06001DFC RID: 7676 RVA: 0x000BCFB0 File Offset: 0x000BB1B0
		private static void TriangulateConstrainedDelaunay(List<List<Vector3>> listlistPointsConstrainedDelaunay, List<List<int>> listlistHashValuesConstrainedDelaunay, bool bForceVertexSoup, FracturedObject fracturedComponent, bool bConnectivityPostprocess, MeshFaceConnectivity faceConnectivityPos, MeshFaceConnectivity faceConnectivityNeg, MeshDataConnectivity meshConnectivityPos, MeshDataConnectivity meshConnectivityNeg, int nForceMeshConnectivityHash, int nSplitCloseSubMesh, Matrix4x4 mtxPlane, Matrix4x4 mtxToLocalPos, Matrix4x4 mtxToLocalNeg, Vector3 v3CenterPos, Vector3 v3CenterNeg, List<int>[] aListIndicesPosInOut, List<VertexData> listVertexDataPosInOut, List<int>[] aListIndicesNegInOut, List<VertexData> listVertexDataNegInOut)
		{
			Matrix4x4 inverse = mtxPlane.inverse;
			List<List<Point2D>> list = new List<List<Point2D>>();
			List<List<PolygonPoint>> list2 = new List<List<PolygonPoint>>();
			List<Polygon> list3 = new List<Polygon>();
			for (int i = 0; i < listlistPointsConstrainedDelaunay.Count; i++)
			{
				List<Point2D> list4 = new List<Point2D>();
				List<PolygonPoint> list5 = new List<PolygonPoint>();
				foreach (Vector3 point in listlistPointsConstrainedDelaunay[i])
				{
					Vector3 vector = inverse.MultiplyPoint3x4(point);
					list4.Add(new Point2D((double)vector.x, (double)vector.z));
					list5.Add(new PolygonPoint((double)vector.x, (double)vector.z));
				}
				list.Add(list4);
				list2.Add(list5);
				list3.Add(new Polygon(list5));
			}
			float num = Mathf.Max(Parameters.EPSILONCAPPRECISIONMIN, fracturedComponent.CapPrecisionFix);
			if (num > 0f)
			{
				for (int j = 0; j < list2.Count; j++)
				{
					double x = list2[j][list2[j].Count - 1].X;
					double y = list2[j][list2[j].Count - 1].Y;
					bool flag = false;
					for (int k = 0; k < list2[j].Count; k++)
					{
						double num2 = list2[j][k].X - x;
						double num3 = list2[j][k].Y - y;
						if (Math.Sqrt(num2 * num2 + num3 * num3) < (double)num)
						{
							list2[j].RemoveAt(k);
							k--;
							if (list2[j].Count < 3)
							{
								flag = true;
								break;
							}
						}
						else
						{
							x = list2[j][k].X;
							y = list2[j][k].Y;
						}
					}
					if (flag)
					{
						list2.RemoveAt(j);
						j--;
					}
				}
			}
			if (list2.Count == 0)
			{
				return;
			}
			int num4 = -1;
			Polygon polygon = null;
			if (!bForceVertexSoup)
			{
				for (int l = 0; l < list2.Count; l++)
				{
					for (int m = 0; m < list2.Count; m++)
					{
						if (l != m && list[l].Count >= 3 && list[m].Count >= 3)
						{
							if (PolygonUtil.PolygonContainsPolygon(list[l], list3[l].Bounds, list[m], list3[m].Bounds, true))
							{
								num4 = l;
								break;
							}
							if (PolygonUtil.PolygonContainsPolygon(list[m], list3[m].Bounds, list[l], list3[l].Bounds, true))
							{
								num4 = m;
								break;
							}
						}
					}
				}
				if (num4 != -1)
				{
					polygon = list3[num4];
					for (int n = 0; n < list2.Count; n++)
					{
						if (n != num4 && list3[n].Count >= 3)
						{
							polygon.AddHole(list3[n]);
						}
					}
				}
			}
			bool flag2 = false;
			if (polygon != null && !bForceVertexSoup)
			{
				try
				{
					P2T.Triangulate(polygon);
					if (polygon.Triangles != null)
					{
						List<Vector3> list6 = new List<Vector3>();
						List<int> list7 = new List<int>();
						Fracturer.CreateIndexedMesh(polygon.Triangles, list6, list7, mtxPlane, true);
						Fracturer.Triangulate(list6, list7, fracturedComponent, listlistPointsConstrainedDelaunay, listlistHashValuesConstrainedDelaunay, bConnectivityPostprocess, faceConnectivityPos, faceConnectivityNeg, meshConnectivityPos, meshConnectivityNeg, nForceMeshConnectivityHash, nSplitCloseSubMesh, mtxPlane, mtxToLocalPos, mtxToLocalNeg, v3CenterPos, v3CenterNeg, aListIndicesPosInOut, listVertexDataPosInOut, aListIndicesNegInOut, listVertexDataNegInOut);
					}
					flag2 = true;
				}
				catch (Exception ex)
				{
					if (fracturedComponent.Verbose)
					{
						Debug.LogWarning(string.Concat(new object[]
						{
							"Exception (",
							ex.GetType(),
							") using hole triangulation (holes = ",
							list2.Count,
							"). Trying to use constrained delaunay."
						}));
					}
					flag2 = false;
				}
			}
			if (!flag2)
			{
				if (bForceVertexSoup)
				{
					List<TriangulationPoint> list8 = new List<TriangulationPoint>();
					if (list2.Count > 0)
					{
						foreach (PolygonPoint item in list2[0])
						{
							list8.Add(item);
						}
						try
						{
							if (list8.Count >= 3)
							{
								PointSet pointSet = new PointSet(list8);
								P2T.Triangulate(pointSet);
								if (pointSet.Triangles != null)
								{
									List<Vector3> list9 = new List<Vector3>();
									List<int> list10 = new List<int>();
									Fracturer.CreateIndexedMesh(pointSet.Triangles, list9, list10, mtxPlane, true);
									Fracturer.Triangulate(list9, list10, fracturedComponent, listlistPointsConstrainedDelaunay, listlistHashValuesConstrainedDelaunay, bConnectivityPostprocess, faceConnectivityPos, faceConnectivityNeg, meshConnectivityPos, meshConnectivityNeg, nForceMeshConnectivityHash, nSplitCloseSubMesh, mtxPlane, mtxToLocalPos, mtxToLocalNeg, v3CenterPos, v3CenterNeg, aListIndicesPosInOut, listVertexDataPosInOut, aListIndicesNegInOut, listVertexDataNegInOut);
								}
							}
						}
						catch (Exception ex2)
						{
							if (fracturedComponent.Verbose)
							{
								Debug.LogWarning("Exception (" + ex2.GetType() + ") using vertex soup triangulation.");
							}
						}
					}
				}
				else
				{
					int num5 = 0;
					foreach (List<PolygonPoint> list11 in list2)
					{
						IList<DelaunayTriangle> list12 = null;
						try
						{
							if (list11.Count >= 3)
							{
								Polygon polygon2 = new Polygon(list11);
								P2T.Triangulate(polygon2);
								list12 = polygon2.Triangles;
							}
						}
						catch (Exception ex3)
						{
							if (fracturedComponent.Verbose)
							{
								Debug.LogWarning(string.Concat(new object[]
								{
									"Exception (",
									ex3.GetType(),
									") using polygon triangulation of cap polygon ",
									num5,
									". Trying to use non constrained"
								}));
							}
							list12 = null;
						}
						if (list12 == null)
						{
							List<TriangulationPoint> list13 = new List<TriangulationPoint>();
							foreach (PolygonPoint item2 in list11)
							{
								list13.Add(item2);
							}
							try
							{
								if (list13.Count >= 3)
								{
									PointSet pointSet2 = new PointSet(list13);
									P2T.Triangulate(pointSet2);
									list12 = pointSet2.Triangles;
								}
							}
							catch (Exception ex4)
							{
								if (fracturedComponent.Verbose)
								{
									Debug.LogWarning(string.Concat(new object[]
									{
										"Exception (",
										ex4.GetType(),
										") using non constrained triangulation of cap polygon ",
										num5,
										". Skipping"
									}));
								}
							}
						}
						if (list12 != null)
						{
							List<Vector3> list14 = new List<Vector3>();
							List<int> list15 = new List<int>();
							Fracturer.CreateIndexedMesh(list12, list14, list15, mtxPlane, true);
							Fracturer.Triangulate(list14, list15, fracturedComponent, listlistPointsConstrainedDelaunay, listlistHashValuesConstrainedDelaunay, bConnectivityPostprocess, faceConnectivityPos, faceConnectivityNeg, meshConnectivityPos, meshConnectivityNeg, nForceMeshConnectivityHash, nSplitCloseSubMesh, mtxPlane, mtxToLocalPos, mtxToLocalNeg, v3CenterPos, v3CenterNeg, aListIndicesPosInOut, listVertexDataPosInOut, aListIndicesNegInOut, listVertexDataNegInOut);
						}
						num5++;
					}
				}
			}
		}

		// Token: 0x06001DFD RID: 7677 RVA: 0x000BD7C8 File Offset: 0x000BB9C8
		private static void CreateIndexedMesh(IList<DelaunayTriangle> listTriangles, List<Vector3> listVerticesOut, List<int> listIndicesOut, Matrix4x4 mtxTransform, bool bTransform)
		{
			listVerticesOut.Clear();
			listIndicesOut.Clear();
			Vector3 zero = Vector3.zero;
			foreach (DelaunayTriangle delaunayTriangle in listTriangles)
			{
				for (int i = 0; i < 3; i++)
				{
					bool flag = false;
					int num = 0;
					TriangulationPoint triangulationPoint = delaunayTriangle.PointCWFrom(delaunayTriangle.Points[i]);
					zero.x = triangulationPoint.Xf;
					zero.z = triangulationPoint.Yf;
					foreach (Vector3 b in listVerticesOut)
					{
						if ((zero - b).magnitude < Parameters.EPSILONDISTANCEVERTEX)
						{
							flag = true;
							break;
						}
						num++;
					}
					if (!flag)
					{
						listIndicesOut.Add(listVerticesOut.Count);
						listVerticesOut.Add(zero);
					}
					else
					{
						listIndicesOut.Add(num);
					}
				}
			}
			if (bTransform)
			{
				for (int j = 0; j < listVerticesOut.Count; j++)
				{
					listVerticesOut[j] = mtxTransform.MultiplyPoint3x4(listVerticesOut[j]);
				}
			}
		}

		// Token: 0x06001DFE RID: 7678 RVA: 0x000BD93C File Offset: 0x000BBB3C
		private static void Triangulate(List<Vector3> listVertices, List<int> listIndices, FracturedObject fracturedComponent, List<List<Vector3>> listlistPointsConstrainedDelaunay, List<List<int>> listlistHashValuesConstrainedDelaunay, bool bConnectivityPostprocess, MeshFaceConnectivity faceConnectivityPos, MeshFaceConnectivity faceConnectivityNeg, MeshDataConnectivity meshConnectivityPos, MeshDataConnectivity meshConnectivityNeg, int nForceMeshConnectivityHash, int nSplitCloseSubMesh, Matrix4x4 mtxPlane, Matrix4x4 mtxToLocalPos, Matrix4x4 mtxToLocalNeg, Vector3 v3CenterPos, Vector3 v3CenterNeg, List<int>[] aListIndicesPosInOut, List<VertexData> listVertexDataPosInOut, List<int>[] aListIndicesNegInOut, List<VertexData> listVertexDataNegInOut)
		{
			int count = listVertexDataPosInOut.Count;
			int count2 = listVertexDataNegInOut.Count;
			if (listVertexDataPosInOut.Count < 1 || listVertexDataNegInOut.Count < 1)
			{
				return;
			}
			VertexData[] array = new VertexData[listVertices.Count];
			VertexData[] array2 = new VertexData[listVertices.Count];
			Vector3 a = mtxPlane.MultiplyVector(Vector3.up);
			float d = (!fracturedComponent.InvertCapNormals) ? 1f : -1f;
			Vector3 v3Normal = mtxToLocalPos.MultiplyVector(-a * d);
			Vector3 v3Normal2 = mtxToLocalNeg.MultiplyVector(a * d);
			Vector3 vector = Vector3.right;
			vector = mtxPlane.MultiplyVector(vector);
			vector = mtxToLocalPos.MultiplyVector(vector);
			Vector3 vector2 = Vector3.right;
			vector2 = mtxPlane.MultiplyVector(vector2);
			vector2 = mtxToLocalNeg.MultiplyVector(vector2);
			Matrix4x4 inverse = mtxPlane.inverse;
			Color32 color = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			Vector3 v = Vector2.zero;
			for (int i = 0; i < listVertices.Count; i++)
			{
				Vector3 vector3 = inverse.MultiplyPoint3x4(listVertices[i]);
				v.x = vector3.x * fracturedComponent.SplitMappingTileU;
				v.y = vector3.z * fracturedComponent.SplitMappingTileV;
				int nVertexHash = Fracturer.ComputeVertexHash(listVertices[i], listlistPointsConstrainedDelaunay, listlistHashValuesConstrainedDelaunay);
				array[i] = new VertexData(nVertexHash, listVertices[i], v3Normal, vector, color, v, v, true, true, listVertexDataPosInOut[0].bHasColor32, listVertexDataPosInOut[0].bHasMapping1, listVertexDataPosInOut[0].bHasMapping2);
				array2[i] = new VertexData(nVertexHash, listVertices[i], v3Normal2, vector2, color, v, v, true, true, listVertexDataNegInOut[0].bHasColor32, listVertexDataNegInOut[0].bHasMapping1, listVertexDataNegInOut[0].bHasMapping2);
			}
			listVertexDataPosInOut.AddRange(array);
			listVertexDataNegInOut.AddRange(array2);
			for (int j = 0; j < listIndices.Count / 3; j++)
			{
				int num = listIndices[j * 3];
				int num2 = listIndices[j * 3 + 1];
				int num3 = listIndices[j * 3 + 2];
				int nVertexHash2 = listVertexDataPosInOut[count + num].nVertexHash;
				int nVertexHash3 = listVertexDataPosInOut[count + num2].nVertexHash;
				int nVertexHash4 = listVertexDataPosInOut[count + num3].nVertexHash;
				int nVertexHash5 = listVertexDataNegInOut[count2 + num].nVertexHash;
				int nVertexHash6 = listVertexDataNegInOut[count2 + num2].nVertexHash;
				int nVertexHash7 = listVertexDataNegInOut[count2 + num3].nVertexHash;
				if (nVertexHash2 != -1 && nVertexHash3 != -1 && nVertexHash4 != -1 && nVertexHash5 != -1 && nVertexHash6 != -1 && nVertexHash7 != -1)
				{
					int nHash = (nForceMeshConnectivityHash != -1) ? nForceMeshConnectivityHash : MeshDataConnectivity.GetNewHash();
					if (fracturedComponent.GenerateChunkConnectionInfo)
					{
						meshConnectivityPos.NotifyNewCapFace(nHash, nSplitCloseSubMesh, aListIndicesPosInOut[nSplitCloseSubMesh].Count / 3);
					}
					aListIndicesPosInOut[nSplitCloseSubMesh].Add(count + num);
					aListIndicesPosInOut[nSplitCloseSubMesh].Add(count + num2);
					aListIndicesPosInOut[nSplitCloseSubMesh].Add(count + num3);
					if (bConnectivityPostprocess)
					{
						faceConnectivityPos.AddEdge(nSplitCloseSubMesh, listVertices[num], listVertices[num2], nVertexHash2, nVertexHash3, count + num, count + num2);
						faceConnectivityPos.AddEdge(nSplitCloseSubMesh, listVertices[num2], listVertices[num3], nVertexHash3, nVertexHash4, count + num2, count + num3);
						faceConnectivityPos.AddEdge(nSplitCloseSubMesh, listVertices[num3], listVertices[num], nVertexHash4, nVertexHash2, count + num3, count + num);
					}
					if (fracturedComponent.GenerateChunkConnectionInfo)
					{
						meshConnectivityNeg.NotifyNewCapFace(nHash, nSplitCloseSubMesh, aListIndicesNegInOut[nSplitCloseSubMesh].Count / 3);
					}
					aListIndicesNegInOut[nSplitCloseSubMesh].Add(count2 + num);
					aListIndicesNegInOut[nSplitCloseSubMesh].Add(count2 + num3);
					aListIndicesNegInOut[nSplitCloseSubMesh].Add(count2 + num2);
					if (bConnectivityPostprocess)
					{
						faceConnectivityNeg.AddEdge(nSplitCloseSubMesh, listVertices[num], listVertices[num3], nVertexHash5, nVertexHash7, count2 + num, count2 + num3);
						faceConnectivityNeg.AddEdge(nSplitCloseSubMesh, listVertices[num3], listVertices[num2], nVertexHash7, nVertexHash6, count2 + num3, count2 + num2);
						faceConnectivityNeg.AddEdge(nSplitCloseSubMesh, listVertices[num2], listVertices[num], nVertexHash6, nVertexHash5, count2 + num2, count2 + num);
					}
				}
			}
		}

		// Token: 0x06001DFF RID: 7679 RVA: 0x000BDDDC File Offset: 0x000BBFDC
		private static int ComputeVertexHash(Vector3 v3Vertex, List<List<Vector3>> listlistPointsConstrainedDelaunay, List<List<int>> listlistHashValuesConstrainedDelaunay)
		{
			float num = float.MaxValue;
			int result = -1;
			for (int i = 0; i < listlistPointsConstrainedDelaunay.Count; i++)
			{
				for (int j = 0; j < listlistPointsConstrainedDelaunay[i].Count; j++)
				{
					float num2 = Vector3.SqrMagnitude(listlistPointsConstrainedDelaunay[i][j] - v3Vertex);
					if (num2 < num)
					{
						result = listlistHashValuesConstrainedDelaunay[i][j];
						num = num2;
					}
				}
			}
			float num3 = Parameters.EPSILONCAPPRECISIONMIN * Parameters.EPSILONCAPPRECISIONMIN;
			if (num > num3)
			{
				return -1;
			}
			return result;
		}

		// Token: 0x06001E00 RID: 7680 RVA: 0x000BDE70 File Offset: 0x000BC070
		private static bool AddCapEdge(Dictionary<EdgeKeyByHash, CapEdge> dicCapEdges, int nVertexHash1, int nVertexHash2, Vector3 v3Vertex1, Vector3 v3Vertex2)
		{
			float fLength = Vector3.Distance(v3Vertex1, v3Vertex2);
			EdgeKeyByHash key = new EdgeKeyByHash(nVertexHash1, nVertexHash2);
			if (!dicCapEdges.ContainsKey(key))
			{
				dicCapEdges.Add(key, new CapEdge(nVertexHash1, nVertexHash2, v3Vertex1, v3Vertex2, fLength));
			}
			return true;
		}

		// Token: 0x06001E01 RID: 7681 RVA: 0x000BDEB0 File Offset: 0x000BC0B0
		private static bool ResolveCap(Dictionary<EdgeKeyByHash, CapEdge> dicCapEdges, List<List<Vector3>> listlistResolvedCapVertices, List<List<int>> listlistResolvedCapHashValues, FracturedObject fracturedComponent)
		{
			if (dicCapEdges.Count < 3)
			{
				if (fracturedComponent.Verbose)
				{
					Debug.LogWarning("Cap has < 3 segments");
				}
				return false;
			}
			listlistResolvedCapVertices.Clear();
			listlistResolvedCapHashValues.Clear();
			List<CapEdge> list = new List<CapEdge>();
			List<CapEdge> list2 = new List<CapEdge>(dicCapEdges.Values);
			List<Vector3> list3 = new List<Vector3>();
			List<int> list4 = new List<int>();
			int count = list2.Count;
			list.Add(list2[0]);
			list3.Add(list2[0].v1);
			list3.Add(list2[0].v2);
			list4.Add(list2[0].nHash1);
			list4.Add(list2[0].nHash2);
			list2.RemoveAt(0);
			while (list2.Count > 0)
			{
				CapEdge capEdge = list[list.Count - 1];
				CapEdge capEdge2 = list[0];
				bool flag = false;
				for (int i = 0; i < list2.Count; i++)
				{
					CapEdge capEdge3 = list2[i];
					int num = capEdge.SharesVertex1Of(capEdge3);
					int num2 = capEdge2.SharesVertex2Of(capEdge3);
					if (num == 2)
					{
						list3.Add(capEdge3.v2);
						list4.Add(capEdge3.nHash2);
						list.Add(capEdge3);
						list2.RemoveAt(i);
						flag = true;
						break;
					}
					if (num2 == 1)
					{
						list3.Insert(0, capEdge3.v1);
						list4.Insert(0, capEdge3.nHash1);
						list.Insert(0, capEdge3);
						list2.RemoveAt(i);
						flag = true;
						break;
					}
				}
				bool flag2 = !flag;
				if (list.Count >= 3 && list[list.Count - 1].SharesVertex1Of(list[0]) == 2)
				{
					flag2 = true;
				}
				if (list2.Count == 0)
				{
					flag2 = true;
				}
				if (flag2)
				{
					int num3 = list3.Count;
					if (Vector3.Distance(list3[0], list3[list3.Count - 1]) < Parameters.EPSILONDISTANCEVERTEX)
					{
						num3 = list3.Count - 1;
					}
					if (num3 > 2)
					{
						List<Vector3> list5 = new List<Vector3>();
						List<int> list6 = new List<int>();
						for (int j = 0; j < num3; j++)
						{
							list5.Add(list3[j]);
							list6.Add(list4[j]);
						}
						listlistResolvedCapVertices.Add(list5);
						listlistResolvedCapHashValues.Add(list6);
					}
					else if (fracturedComponent.Verbose)
					{
						Debug.LogWarning("Cap group has less than 3 vertices (" + list3.Count + ")");
					}
					if (list2.Count > 0)
					{
						list.Clear();
						list.Add(list2[0]);
						list3.Clear();
						list4.Clear();
						list3.Add(list2[0].v1);
						list3.Add(list2[0].v2);
						list4.Add(list2[0].nHash1);
						list4.Add(list2[0].nHash2);
						list2.RemoveAt(0);
					}
				}
			}
			if (list2.Count > 0 && fracturedComponent.Verbose)
			{
				Debug.LogWarning(string.Format("Cap has {0}/{1} unresolved segments left", list2.Count, count));
			}
			return true;
		}

		// Token: 0x04001E15 RID: 7701
		private static Fracturer.FracturingStats s_FracturingStats = new Fracturer.FracturingStats();

		// Token: 0x02000426 RID: 1062
		private class FracturingStats
		{
			// Token: 0x06001E03 RID: 7683 RVA: 0x000BE23B File Offset: 0x000BC43B
			public FracturingStats()
			{
				this.nChunkCount = 0;
				this.nTotalChunks = 0;
				this.nSplitCount = 0;
				this.bCancelFracturing = false;
			}

			// Token: 0x04001E16 RID: 7702
			public int nChunkCount;

			// Token: 0x04001E17 RID: 7703
			public int nTotalChunks;

			// Token: 0x04001E18 RID: 7704
			public int nSplitCount;

			// Token: 0x04001E19 RID: 7705
			public bool bCancelFracturing;
		}

		// Token: 0x02000427 RID: 1063
		// (Invoke) Token: 0x06001E05 RID: 7685
		public delegate void ProgressDelegate(string strTitle, string message, float fT);

		// Token: 0x02000428 RID: 1064
		private class SpaceTreeNode
		{
			// Token: 0x06001E08 RID: 7688 RVA: 0x000BE25F File Offset: 0x000BC45F
			public SpaceTreeNode()
			{
				this.nodeOneSide = null;
				this.nodeOtherSide = null;
				this.listMeshDatasSpace = new List<MeshData>();
				this.nLevel = 0;
				this.nSplitsX = 0;
				this.nSplitsY = 0;
				this.nSplitsZ = 0;
			}

			// Token: 0x06001E09 RID: 7689 RVA: 0x000BE29C File Offset: 0x000BC49C
			public bool ContainsCompletely(Vector3 v3Min, Vector3 v3Max)
			{
				return ((this.v3Min.x <= v3Min.x && this.v3Max.x >= v3Max.x) || this.nSplitsX == 0) && ((this.v3Min.y <= v3Min.y && this.v3Max.y >= v3Max.y) || this.nSplitsY == 0) && ((this.v3Min.z <= v3Min.z && this.v3Max.z >= v3Max.z) || this.nSplitsZ == 0);
			}

			// Token: 0x06001E0A RID: 7690 RVA: 0x000BE358 File Offset: 0x000BC558
			public static List<MeshData> GetSmallestPossibleMeshData(Fracturer.SpaceTreeNode root, Vector3 v3Min, Vector3 v3Max)
			{
				if (!root.ContainsCompletely(v3Min, v3Max))
				{
					return root.listMeshDatasSpace;
				}
				Fracturer.SpaceTreeNode spaceTreeNode = root;
				for (;;)
				{
					if (spaceTreeNode.nodeOneSide != null && spaceTreeNode.nodeOneSide.ContainsCompletely(v3Min, v3Max))
					{
						spaceTreeNode = spaceTreeNode.nodeOneSide;
					}
					else
					{
						if (spaceTreeNode.nodeOtherSide == null || !spaceTreeNode.nodeOtherSide.ContainsCompletely(v3Min, v3Max))
						{
							break;
						}
						spaceTreeNode = spaceTreeNode.nodeOtherSide;
					}
				}
				return spaceTreeNode.listMeshDatasSpace;
			}

			// Token: 0x06001E0B RID: 7691 RVA: 0x000BE3E0 File Offset: 0x000BC5E0
			public static Fracturer.SpaceTreeNode BuildSpaceTree(MeshData meshDataIn, int nSubdivisionLevels, FracturedObject fracturedComponent, Fracturer.ProgressDelegate progress = null)
			{
				if (nSubdivisionLevels < 1)
				{
					return null;
				}
				Fracturer.SplitOptions splitOptions = new Fracturer.SplitOptions();
				splitOptions.bForceNoIslandGeneration = true;
				splitOptions.bForceNoChunkConnectionInfo = true;
				splitOptions.bForceNoIslandConnectionInfo = true;
				splitOptions.bForceNoCap = false;
				splitOptions.bVerticesAreLocal = true;
				Fracturer.SpaceTreeNode spaceTreeNode = new Fracturer.SpaceTreeNode();
				spaceTreeNode.listMeshDatasSpace = new List<MeshData>();
				spaceTreeNode.listMeshDatasSpace.Add(meshDataIn);
				spaceTreeNode.nLevel = 0;
				spaceTreeNode.nSplitsX = 0;
				spaceTreeNode.nSplitsY = 0;
				spaceTreeNode.nSplitsZ = 0;
				spaceTreeNode.v3Min = meshDataIn.v3Min;
				spaceTreeNode.v3Max = meshDataIn.v3Max;
				Queue<Fracturer.SpaceTreeNode> queue = new Queue<Fracturer.SpaceTreeNode>();
				queue.Enqueue(spaceTreeNode);
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				int num4 = 0;
				int num5 = 0;
				for (int i = 0; i < nSubdivisionLevels; i++)
				{
					num += Mathf.RoundToInt(Mathf.Pow(2f, (float)i));
				}
				while (queue.Count > 0)
				{
					Fracturer.SpaceTreeNode spaceTreeNode2 = queue.Dequeue();
					if (spaceTreeNode2.nLevel < nSubdivisionLevels)
					{
						if (progress != null)
						{
							progress("Fracturing", string.Format("Pre computing space volume (split {0}/{1}, Depth {2})", num2 + 1, num, spaceTreeNode2.nLevel + 1), Mathf.Clamp01((float)num2 / (float)num));
						}
						if (Fracturer.IsFracturingCancelled())
						{
							return null;
						}
						Vector3 v3PlaneNormal = Vector3.up;
						Vector3 v3PlaneRight = Vector3.right;
						Vector3 v3PlanePoint = (spaceTreeNode2.v3Min + spaceTreeNode2.v3Max) * 0.5f;
						float num6 = spaceTreeNode2.v3Max.x - spaceTreeNode2.v3Min.x;
						float num7 = spaceTreeNode2.v3Max.y - spaceTreeNode2.v3Min.y;
						float num8 = spaceTreeNode2.v3Max.z - spaceTreeNode2.v3Min.z;
						Vector3 vector = spaceTreeNode2.v3Min;
						Vector3 vector2 = spaceTreeNode2.v3Max;
						Vector3 vector3 = spaceTreeNode2.v3Min;
						Vector3 vector4 = spaceTreeNode2.v3Max;
						if (num6 >= num7 && num6 >= num8)
						{
							v3PlaneNormal = Vector3.right;
							v3PlaneRight = Vector3.forward;
							vector2.x = v3PlanePoint.x;
							vector3.x = v3PlanePoint.x;
							num3++;
						}
						else if (num7 >= num6 && num7 >= num8)
						{
							v3PlaneNormal = Vector3.up;
							v3PlaneRight = Vector3.right;
							vector2.y = v3PlanePoint.y;
							vector3.y = v3PlanePoint.y;
							num4++;
						}
						else
						{
							v3PlaneNormal = Vector3.forward;
							v3PlaneRight = Vector3.right;
							vector2.z = v3PlanePoint.z;
							vector3.z = v3PlanePoint.z;
							num5++;
						}
						foreach (MeshData meshDataIn2 in spaceTreeNode2.listMeshDatasSpace)
						{
							List<MeshData> list;
							List<MeshData> list2;
							if (Fracturer.SplitMeshUsingPlane(meshDataIn2, fracturedComponent, splitOptions, v3PlaneNormal, v3PlaneRight, v3PlanePoint, out list, out list2, progress))
							{
								spaceTreeNode2.nodeOneSide = new Fracturer.SpaceTreeNode();
								spaceTreeNode2.nodeOneSide.listMeshDatasSpace = list2;
								spaceTreeNode2.nodeOneSide.v3Min = vector;
								spaceTreeNode2.nodeOneSide.v3Max = vector2;
								spaceTreeNode2.nodeOneSide.nLevel = spaceTreeNode2.nLevel + 1;
								spaceTreeNode2.nodeOneSide.nSplitsX = num3;
								spaceTreeNode2.nodeOneSide.nSplitsY = num4;
								spaceTreeNode2.nodeOneSide.nSplitsZ = num5;
								queue.Enqueue(spaceTreeNode2.nodeOneSide);
								spaceTreeNode2.nodeOtherSide = new Fracturer.SpaceTreeNode();
								spaceTreeNode2.nodeOtherSide.listMeshDatasSpace = list;
								spaceTreeNode2.nodeOtherSide.v3Min = vector3;
								spaceTreeNode2.nodeOtherSide.v3Max = vector4;
								spaceTreeNode2.nodeOtherSide.nLevel = spaceTreeNode2.nLevel + 1;
								spaceTreeNode2.nodeOtherSide.nSplitsX = num3;
								spaceTreeNode2.nodeOtherSide.nSplitsY = num4;
								spaceTreeNode2.nodeOtherSide.nSplitsZ = num5;
								queue.Enqueue(spaceTreeNode2.nodeOtherSide);
							}
						}
						num2++;
					}
				}
				return spaceTreeNode;
			}

			// Token: 0x04001E1A RID: 7706
			private Fracturer.SpaceTreeNode nodeOneSide;

			// Token: 0x04001E1B RID: 7707
			private Fracturer.SpaceTreeNode nodeOtherSide;

			// Token: 0x04001E1C RID: 7708
			private int nLevel;

			// Token: 0x04001E1D RID: 7709
			private int nSplitsX;

			// Token: 0x04001E1E RID: 7710
			private int nSplitsY;

			// Token: 0x04001E1F RID: 7711
			private int nSplitsZ;

			// Token: 0x04001E20 RID: 7712
			private Vector3 v3Min;

			// Token: 0x04001E21 RID: 7713
			private Vector3 v3Max;

			// Token: 0x04001E22 RID: 7714
			private List<MeshData> listMeshDatasSpace;
		}

		// Token: 0x02000429 RID: 1065
		public class SplitOptions
		{
			// Token: 0x06001E0C RID: 7692 RVA: 0x000BE808 File Offset: 0x000BCA08
			public SplitOptions()
			{
				this.bForceNoProgressInfo = false;
				this.bForceNoIslandGeneration = false;
				this.bForceNoChunkConnectionInfo = false;
				this.bForceNoIslandConnectionInfo = false;
				this.bForceNoCap = false;
				this.bForceCapVertexSoup = false;
				this.bIgnoreNegativeSide = false;
				this.bVerticesAreLocal = false;
				this.nForceMeshConnectivityHash = -1;
			}

			// Token: 0x04001E23 RID: 7715
			public static Fracturer.SplitOptions Default = new Fracturer.SplitOptions();

			// Token: 0x04001E24 RID: 7716
			public bool bForceNoProgressInfo;

			// Token: 0x04001E25 RID: 7717
			public bool bForceNoIslandGeneration;

			// Token: 0x04001E26 RID: 7718
			public bool bForceNoChunkConnectionInfo;

			// Token: 0x04001E27 RID: 7719
			public bool bForceNoIslandConnectionInfo;

			// Token: 0x04001E28 RID: 7720
			public bool bForceNoCap;

			// Token: 0x04001E29 RID: 7721
			public bool bForceCapVertexSoup;

			// Token: 0x04001E2A RID: 7722
			public bool bIgnoreNegativeSide;

			// Token: 0x04001E2B RID: 7723
			public bool bVerticesAreLocal;

			// Token: 0x04001E2C RID: 7724
			public int nForceMeshConnectivityHash;
		}
	}
}
